问题描述
如果我在我的MainModule.js中定义了一个像这样的常量,那么这个常量就包含在这个常量中在主html文件的开头
> var myApp = angular.module('AC'.....);
> myApp.constant( timeoutValue,5);
我可以通过传递timeoutValue来访问我的controller.js中的常量。
但我无法在我的template.html / partial中访问它。
如何在我的template.html / partial file中访问timeoutValue / p>
将其注入到控制器中并为其设置一个范围变量。
app.constant('timeoutValue',5);
$ b app.controller('someController',function($ scope,timeoutValue){
$ scope.timeoutValue = timeoutValue;
});
How do i access constants defined in common js file into template of different module.
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);
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.
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;
});
这篇关于如何访问Angulajs模板中的常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!