[英]ng-show comparing with a variable
given following example 给出以下示例
<div class="progress-animation" ng-show="file.state == STATES.DOWNLOADING">
<div class="loader">Loading...</div>
</div>
in javascript I've all these constants defined at a global level initialized before angular kicks in. 在javascript中,我将所有这些常量定义为在全局范围内定义的值,然后再进行角踢。
STATES = {
DOWNLOADING: 1,
UPDATING: 2,
INSTALLING: 3
}
it works with file.state == 1
but wondering how angular can evaluate it as an expression. 它与
file.state == 1
一起工作,但想知道angular如何将其作为表达式求值。
使用$scope.STATES
将STATES
暴露给您的视图,这应该可以解决问题
if you defined in your controller 如果您在控制器中定义
$scope.STATES = STATES;
your binding should work. 您的绑定应该起作用。 good luck!
祝好运!
You could assign the value to $rootScope
- seems to be one of few cases where it would be acceptable - to make it work app-wide: 您可以将值分配给
$rootScope
似乎是少数可以接受的情况-使它在整个应用程序中都可以运行:
var STATES = {...}
app.run(function($rootScope){
$rootScope.STATES = STATES;
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.