我有以下 Angular 模块。我如何从我的 Controller 之一调用 APIHost?
angular.module('configuration', [])
.constant('APIHost','http://api.com')
.constant('HostUrl','http://example.com')
.constant('SolutionName', 'MySite');
最佳答案
Constant只不过是一种提供者配方。
您需要在controller
工厂函数中注入(inject)constant
依赖项,就是这样。
app.controller('testCtrl', function($scope, APIHost){
console.log(APIHost)
})
Make sure your
configuration
module has been added to main module as dependency to get use ofconstant
's provider like below
var app = angular.module('app', ['configuration', 'otherdependency']);
app.controller( ... ) //here you can have configuration constant available
关于javascript - 调用模块常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35752464/