当数组长度为零时,angularjs – ng-show
发布时间:2020-12-17 08:29:27 所属栏目:安全 来源:网络整理
导读:我是AngularJS的初学者。我在“ng-show”的帮助下,在过滤过程中尝试显示“No Tag Found”。 JS: function simpleController($scope){$scope.tags = ['HTML','CSS','Jquery','Bootstrap','AngularJS'];} HTML: div ng-controller="simpleController"input
我是AngularJS的初学者。我在“ng-show”的帮助下,在过滤过程中尝试显示“No Tag Found”。
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/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |