如果过滤了一系列商品且没有匹配的商品,我想展示“没有商品”。
vm.items = [
{name: '1', type: 1},
{name: '2', type: 2},
{name: '1.2', type: 1},
];
<ul>
<li ng-repeat="item in vm.items | filter: {type:1}>
{{item.name}}
</li>
<li ng-repeat="item in vm.items | filter: {type:1} ?? length === 0>
No items
</li>
</ul>
答案 0 :(得分:2)
在这里,您可以使用ng-if
指令filtered.length
ng-repeat
数据及其别名
<ul>
<li ng-repeat="item in vm.items | filter: {type:1} as filtered">
{{item.name}}
</li>
<li ng-if="!filtered.length">
No items
</li>
</ul>
答案 1 :(得分:1)
这是一个记住过滤器数量的巧妙技巧:
<ul>
<li ng-repeat="item in (filtered = vm.items | filter: {type:1})>
{{item.name}}
</li>
<li ng-if="filtered.length == 0">
No items
</li>
</ul>