I want to add some headers before calling $http’s get method. I tried this:
$http = $originalHttpMethod;
this.$http = function() {
//add headers
return $http
};
$http.get({url:'http://...'});
but i get this error:
TypeError: Object function () {return $http} has no method ‘get’.
I want to do this without crash original class.
How can i done this ?
Make a service instead of doing anything local. This way you can reuse it much easier across your application.
And then inside your controllers, directives or any other services, just include it as a dependency and use it like so:
Here’s some more info about that:
http://www.yearofmoo.com/2012/10/more-angularjs-magic-to-supercharge-your-webapp.html#you-should-be-using-custom-services