angularjs – 如何在ng-if和变量中使用过滤器?

前端之家收集整理的这篇文章主要介绍了angularjs – 如何在ng-if和变量中使用过滤器?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在这个例子中,我在 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}
];
你能试试吗
<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>
原文链接:https://www.f2er.com/angularjs/142877.html

猜你在找的Angularjs相关文章