如何访问Angulajs模板中的常量 [英] How to access constants in Angulajs Template

查看:121
本文介绍了如何访问Angulajs模板中的常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我在我的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模板中的常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆