条件NG-类不工作 [英] Condition in ng- class not working

查看:192
本文介绍了条件NG-类不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AngularJS

我有应用类的情况下根据我敢动态存储rootscope的价值和在HTML评价角度的前pression但仍无法正常工作的条件。

I have scenario of applying class based on a condition in which I'm storing the value in rootscope dynamically and evaluating in html angular expression but still not working

<li role="presentation" style="width:200px" ng-class="{active: true, inactive: false}[{{vm.$rootScope.currentPage}}==1]"><a href="#/create">Create</a></li>

在检查元素,如果我检查,我可以看到1 == 1,但仍然类是没有得到积极和如果我删除{{VM。$ rootScope.currentPage}}及地点1,它正在

In inspect element if I check I can see 1==1 but still class is not getting active and if I remove {{vm.$rootScope.currentPage}} and place 1 it is working

我想这也是

<li role="presentation" style="width:200px" ng-class="{'active':2=={{vm.$rootScope.currentPage}} }"><a href="#/include">include</a></li>

与同样的事情我也可以看到2 == 2,但仍然没有激活和如果Istatically地方2 == 2,它正在

推荐答案

您在写不对,这样做:

ng-class="{'active': true, 'inactive': false}

类的名头则条件。

The class name first then the condition.

和本:

ng-class="{'active': 2 === vm.$rootScope.currentPage}"

没有额外的括号内,因为它已经是一个前pression。

No extra brackets inside because it's already an expression.

这篇关于条件NG-类不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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