简体   繁体   English

ng-class 的多个参数不起作用

[英]multiple arguments for ng-class not working

I have two parameters I'm trying to check to set a class with ng-class, but for some reason it will only work with one.我有两个参数我正在尝试检查以使用 ng-class 设置一个类,但由于某种原因它只能使用一个。

Here is my code:这是我的代码:

ng-class="{'alert-viewed':item.viewed && item.status <= 0}

If is just us 'alert-viewed':item.viewed it works.如果只是我们 'alert-viewed':item.viewed 它有效。 But adding on the item.status check breaks it.但是添加 item.status 检查会破坏它。

Anyone see what I'm missing?有人看到我缺少什么吗?

The order of operations is wrong in your expression.您的表达式中的操作顺序是错误的。 Because && has a higher precedence than <= , your flags are being evaluated first, then compared to <=0 .因为&&的优先级高于<= ,所以首先评估您的标志,然后与<=0进行比较。 Instead, you want the second half of your expression to be evaluated first, and then evaluated against the first half, which means you need parenthesis around the second half of the statement.相反,您希望先计算表达式的后半部分,然后针对前半部分进行计算,这意味着您需要在语句的后半部分周围加上括号。

ng-class="{'alert-viewed':item.viewed && (item.status <= 0)}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM