发现了一个 Angularjs ng-show ng-if 的错误

found a bug for angularjs ng-show ng-if?

本文关键字:ng-show Angularjs ng-if 错误 一个 发现      更新时间:2023-09-26

我发现了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中,它不能正常工作。

这是一个错误吗?

上述所有语句都是无效语句。我给你举个例子。

 //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/if。你总是需要一个可以计算真或假的表达式,或者一个将返回真或假的函数。不要将 html 中的角度等同于你的 JavaScript。