Reputation: 493
I'd like to have constant that is accessible from my other modules. I tried something like below, but there's exception. How should I modify my code to make it work?
angular.module('starter', ['starter.Authentication'])
.constant('baseUrl', 'http://myUrl/api/');
angular.module('starter.Authentication', ['baseUrl'])
.factory('AuthenticationService',
['baseUrl',
function (baseUrl) {
var service = {};
return service;
};
Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:
Error: [$injector:modulerr] Failed to instantiate module starter.Authentication due to:
Error: [$injector:modulerr] Failed to instantiate module baseUrl due to:
Error: [$injector:nomod] Module 'baseUrl' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
Upvotes: 1
Views: 106
Reputation: 30098
Change:
angular.module('starter.Authentication', ['baseUrl'])
To:
angular.module('starter.Authentication', ['starter'])
This is because starter
is a module that holds the baseUrl
constant.
Upvotes: 1