如何将普通js文件中定义的常量访问到不同模块的模板中。
如果我在我的 MainModule.js 中定义了一个像这样的常量,它包含在主 html 文件的开头
> var myApp = angular.module('AC' .....);
> myApp.constant('timeoutValue',5);
通过将“timeoutValue”传递给它,我能够访问我的 controller.js 中的常量。 但是我无法在我的 template.html/partial 中访问它。
如何在我的 template.html/partial 文件中访问“timeoutValue”
最佳答案
将它注入(inject)到您的 Controller 中并为其设置一个作用域变量。
app.constant('timeoutValue', 5);
app.controller('someController', function($scope, timeoutValue) {
$scope.timeoutValue = timeoutValue;
});
关于angularjs - 如何在 Angularjs 模板中访问常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24338261/