gpt4 book ai didi

angularjs - ng-show当数组长度为零时

转载 作者:行者123 更新时间:2023-12-03 08:52:02 25 4
gpt4 key购买 nike

我是AngularJS的初学者。我正在尝试通过“ 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>

当我键入除数组值以外的任何值时,我无法使用以上代码获得“找不到标签”。请帮忙。谢谢。

最佳答案

如果要过滤ng-repeat,则必须对ng-show应用相同的过滤器。如果不这样做,ng-show将始终引用整个数组:

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

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

关于angularjs - ng-show当数组长度为零时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23076570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com