Issue
Code:
angular.module('appName').factory('serviceName', ['$http', function ($http) {
Here, I am making Angular's $http service available to my service but how do I make it available to all services in my app without having to define it every time in every service within the app (assuming every service in my app needs access to $http)?
There seems to be very little help on this issue.
Solution
angular.module('appName').factory('globalize', ['$http', function ($http) {
window.$http = $http;
}]);
e.g http://plnkr.co/edit/HbyX2Bx8c3TNJyvL2ljf?p=preview
there you go, it's global now. But this is not the best thing to do...
Answered By - yangli-io
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.