发现了angularjs ng-show ng-if的错误?

时间:2016-02-09 12:08:30

标签: javascript angularjs

我发现了angularjs的几个错误:

<div ng-show="['[]']">this should be show but actually not</div>
<div ng-show="[]">this should be show but actually not</div>
<div ng-show="[0]">this should be show but actually not</div>
<div ng-show="['0']">this should be show but actually not</div>

当在javascript中的if语句中使用这些条件时,它们被视为true。 但在ng-showng-hideng-if中,它无效。

这是一个错误吗?

1 个答案:

答案 0 :(得分:-1)

以上所有陈述均为无效陈述。我会举例说明。

 //What you have done here  is created an array with a string of '[]' which has no expression to return true or false;
<div ng-show="['[]']">this should be show but actually not</div>

// Here is just an empty array again with no expression to return true or false. Better use would be myArray.length > 0 which will evaluate as true or false;
<div ng-show="[]">this should be show but actually not</div>

 //Here is just like the first one except you have an array of one number being 0 which will still never evaluate to a true or false;
<div ng-show="[0]">this should be show but actually not</div>

 //I dont think this one needs any explaining as you can see the pattern from above;
<div ng-show="['0']">this should be show but actually not</div>

您没有正确使用ng-show /。您总是需要一个可以评估true或false的表达式,或者一个返回true或false的函数。不要将html中的角度等同于你的javascript。