如何在Angularjs模板中访问常量 [英] How to access constants in Angularjs Template
本文介绍了如何在Angularjs模板中访问常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将通用js文件中定义的常量访问不同模块的模板.
How do I access constants defined in common js file into template of different module.
如果我在MainModule.js中定义了这样的常量,该常量包含在主html文件的开头
if I have defined a constant like this in my MainModule.js which is included in the beginning of the main html file
> var myApp = angular.module('AC' .....);
> myApp.constant('timeoutValue',5);
我可以通过将"timeoutValue"传递给我的controller.js中的常量. 但是我无法在我的template.html/partial中访问它.
I was able to access my constant in my controller.js by passing "timeoutValue" to it. But I am unable to access it in my template.html/partial.
如何访问template.html/部分文件中的"timeoutValue"
How can I access "timeoutValue" in my template.html/partial file
推荐答案
将其注入控制器并为其设置范围变量.
Inject it into your controller and set a scope variable to it.
app.constant('timeoutValue', 5);
app.controller('someController', function($scope, timeoutValue) {
$scope.timeoutValue = timeoutValue;
});
这篇关于如何在Angularjs模板中访问常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文