I've been searching and so far I couldn't find a way to handle the following situation:
I'd like to have one variable that represents my domain, something like http://example.com/myserver/
. Anything that I would want to access is sublocaled in that domain. Such variable should be available for me in all Services
as well as from HTML (for image loading purpose). For instance:
angular.module('App', ['App.providers', 'App.services', 'App.controllers', 'App.directives']).run('EndpointFactory', [function (EndpointFactory) {
EndpointFactory.BASE = 'http://www.example.com/mydata';
}]);
angular.module('App.services', []).factory('PrizeService', ['$http', 'EndpointFactory', function ($http, EndpointFactory) {
return {
index: function () {
return $http.post(EndpointFactory.BASE + '/prizes', {});
}
};
}]);
This example above was one of my failed trials. Although I don't like the idea of having to inject a Factory at every Service, I was willing to do it until I faced the <img ng-src />
tag.
<div>
<img ng-src="{{EndpointFactory.BASE + prize.imagePath}}" />
</div>
I can't access the EndpointFactory from this directive and I don't want to have to copy data from the factory to a $scope
in every controller.