Angular: $injector 14415845
http://angularjs.org/
by jochenvanwylick
HTML
<div id="div1" ng-controller="MyCtrl">
<ul>
<li>{{m1}}</li>
<li>{{m2}}</li>
<li>{{m3}}</li>
<li>{{m4}}</li>
</ul>
</div>
JavaScript
var Constants = Constants || {};
Constants.WebAPIUrlMap = {
Google: 'www.google.com',
Bing: 'www.bing.com'
};
var myApp = angular.module('myApp',[]);
myApp.service('apiClientFactory', function() {
return {
build: function(url) {
// this captures the passed url into the returned closure
var serviceUrl = url;
return {
Get: function() {
return 'Getting from URL ' + serviceUrl;
},
Post: function() {
return 'Posting to URL ' + serviceUrl;
}
};
}
};
});
myApp.controller('MyCtrl', ['$scope', 'apiClientFactory', function($scope, $factory) {
// AngularJS injects singletons. So let's inject a factory then and instantiate
// the services ourselves with the correct configuration
$scope.serviceOne = $factory.build(Constants.WebAPIUrlMap.Google);
$scope.serviceTwo = $factory.build(Constants.WebAPIUrlMap.Bing);
//debugger;
$scope.m1 = $scope.serviceOne.Get();
$scope.m2 = $scope.serviceOne.Post();
$scope.m3 = $scope.serviceTwo.Get();
$scope.m4 = $scope.serviceTwo.Post();
}]);