当数组长度为零时显示ng-show

use*_*497 31 angularjs

我是AngularJS的初学者.我想显示"无标签找到"期间的"帮助过滤过程NG秀 ".

JS:

function simpleController($scope)
{
$scope.tags = ['HTML','CSS','Jquery','Bootstrap','AngularJS'];
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

当我输入除数组值之外的任何值时,我无法使用上面的代码获得"No Tag Found".请帮忙.谢谢.

Cét*_*tia 43

如果你在你的筛选ng-repeat,必须应用相同的过滤器你 ng-show.如果你不这样做,ng-show将始终指全排列:

<div ng-show="!(tags| filter:nameText).length">No Tag Found</div>
Run Code Online (Sandbox Code Playgroud)

工作小提琴:http://jsfiddle.net/HB7LU/3149/


gur*_*gui 19

更好地使用ng-hide:

<div ng-hide="tags.length">No Tag Found</div>
Run Code Online (Sandbox Code Playgroud)


Can*_*mak 11

 <div class="box" ng-show="team_stores.length > 0" >   
Run Code Online (Sandbox Code Playgroud)

为我工作