NG-show当数组的长度为零 [英] ng-show when array length is zero
本文介绍了NG-show当数组的长度为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是AngularJS初学者。我想显示无标签找到在过滤过程中的帮助下 NG-节目
I am a beginner for AngularJS. I am trying to display "No Tag Found" during filter process with the help of "ng-show".
JS:
function simpleController($scope)
{
$scope.tags = ['HTML','CSS','Jquery','Bootstrap','AngularJS'];
}
HTML:
<div ng-controller="simpleController">
<input class="txt" type="text" ng-model="nameText" />
<div>
<ul>
<li ng-repeat="myKeys in tags| filter:nameText">{{myKeys}}</li>
</ul>
<div ng-show="!tags.length">No Tag Found</div>
</div>
</div>
当我键入比阵列的山谷以外的任何值,我没能获得无标签找到使用上述code。请帮忙。谢谢你。
When I type any value other than array vales, I am not able to get "No Tag Found" using the above code. Please help. Thanks.
推荐答案
如果你在你的 NG-重复
,则必须采用同样的过滤器过滤你 NG-节目
。如果你不这样做, NG-节目
总是引用完整数组:
If you're filtering in your ng-repeat
, you must apply the same filter for you ng-show
. If you don't, the ng-show
will always refer to the full array :
<div ng-show="!(tags| filter:nameText).length">No Tag Found</div>
工作小提琴: http://jsfiddle.net/HB7LU/3149/
这篇关于NG-show当数组的长度为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文