angularjs - Angular Config Doesn't Work -
i have following code. console.log(apiserverconstants.url)
line in factory returns undefined
when inject authservice in other code. why?
angular.module("webclient.constants", []) .constant("apiserverconstants", { "url": "http://localhost:8080" }); angular.module('webclient', [ // stuff 'webclient.constants' ]) .config( // code }); angular.module('webclient') .factory('authservice', ['$http', 'apiserverconstants', 'localstorageservice', function($http, localstorageservice, apiserverconstants) { return { authenticate: function(data) { // code }, login: function(data, apiserverconstants) { console.log(data); console.log(apiserverconstants.url); // more code } } }]);
you inverted injections.
['$http', 'apiserverconstants', 'localstorageservice', function($http, localstorageservice, apiserverconstants)
should ['$http', 'localstorageservice', 'apiserverconstants', function($http, localstorageservice, apiserverconstants)
edit:
and why apiserverconstants
parameter of login
? try this:
login: function(data) { console.log(apiserverconstants.url); }
Comments
Post a Comment