我想从我的其他模块中获取常量。 我试过像下面这样的东西,但有例外。 我应该如何修改我的代码才能使其正常工作?
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.
答案 0 :(得分:1)
变化:
angular.module('starter.Authentication', ['baseUrl'])
要:
angular.module('starter.Authentication', ['starter'])
这是因为starter
是一个保持baseUrl
常量的模块。