如何将通用js文件中定义的常量访问到不同模块的模板中。
如果我在包含在主html文件开头的MainModule.js中定义了如下常量
> var myApp = angular.module('AC' .....);
> myApp.constant('timeoutValue',5);通过将"timeoutValue“传递给它,我能够访问我controller.js中的常量。但是我无法在我的template.html/partial中访问它。
如何访问template.html/partial文件中的"timeoutValue“
发布于 2014-06-21 12:28:44
将其注入到控制器中,并为其设置一个作用域变量。
app.constant('timeoutValue', 5);
app.controller('someController', function($scope, timeoutValue) {
$scope.timeoutValue = timeoutValue;
});发布于 2016-04-15 18:32:52
尝试将常量分配给$rootScope并在模板中使用。
myModule.constant('brand', 'MyBrand');
myModule.run(['$rootScope','brand', function ($rootScope,brand) {
$rootScope.brand = brand;
}]); https://stackoverflow.com/questions/24338261
复制相似问题