-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility with Angular's $http/$q services #37
Comments
I didn't tried, but 👍 . Using |
There's definitely room for a simple wrapper, but that's out of scope for this library. Happy to link to an Angular plugin/wrapper/extension from here if someone wants to take that on. |
If you are interested, here is my wrapper function for angular.module('my.app', []).run ($http) ->
HyperAgent.configure 'ajax', (options) ->
# Ensure success/error callbacks are called as HyperAgent relies
# on these to resolve its promise
$http(options)
.then (resp) -> options.success(resp.data)
.catch(options.error)
HyperAgent.configure('defer', $q.defer) |
In order to get angular to play nice with Hyperagent, you need to make sure angular doesn't parse the result. angular doesn't respect the angular.module('app', []).run(['$http', '$q', function ($http, $q) {
Hyperagent.configure('defer', $q.defer);
Hyperagent.configure('ajax', function (options) {
options.transformResponse = function (data) {
return data;
};
return $http(options)
.success(options.success)
.catch(options.error);
});
}]); |
I'm wondering if anyone has attempted to get angular's native $http service to work as the request lib Hyperagent uses?
It seems straightforward to decorate $http accordingly but I haven't tried it myself yet because I'm in a project where we've accepted
jQuery.ajax
long ago.The important issue here is making Angular aware of requests HA is making so as to work seamlessly with Angular's internals (interceptors and so forth)
The text was updated successfully, but these errors were encountered: