Javascript 发现angularjs ng show ng的错误如果?
我发现angularjs有几个bug:Javascript 发现angularjs ng show ng的错误如果?,javascript,angularjs,Javascript,Angularjs,我发现angularjs有几个bug: <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> <di
<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 show、ng hide、ng if中,它不能正常工作
这是一个bug吗?以上所有语句都是无效语句。我给你们举个例子
//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。您总是需要一个可以计算true或false的表达式,或者一个将返回true或false的函数。不要将html中的角度表达式等同于javascript。为什么要使用数组代替布尔值?空数组在角度表达式中的计算结果按设计为false。关于angularjs,请参见api文档,它只告诉truthy或falsy。我认为它只意味着正确或错误。