在这个例子中,我在
ng-repeat
中使用过滤器,但是如何在变量和ng-if中使用它,如下所示:
{{languages.length | filter: {available: true}}}
和
ng-if="languages.length == 0 | filter: {available: true}"
见Fiddle.
HTML
<div ng-controller="mainController"> <div>There are {{languages.length}} languages in total.</div> <div>??? There are {{languages.length}} languages available.</div> <div ng-if="languages.length == 0">??? Sorry,there are no languages available.</div> <ol> <li ng-repeat="language in languages | filter: {available: true}">{{language.name}}</li> </ol> </div>
AngularJS
$scope.languages = [ {id:1,name:"German",available: false},{id:2,name:"English",available: true},{id:3,name:"French",{id:4,name:"Italian",{id:5,name:"Spanish",available: false} ];
你能试试吗
原文链接:https://www.f2er.com/angularjs/142877.html<div ng-controller="mainController"> <div>There are {{languages.length}} languages in total.</div> <div>There are {{(languages|filter:{available:true}).length}} languages available.</div> <div ng-if="(languages|filter:{available:true}).length == 0">Sorry,there are no languages available.</div> <ol> <li ng-repeat="language in languages | filter: {available: true}">{{language.name}}</li> </ol> </div>