我在视图中
<tr ng-repeat="entry in entryList | myfilter1">
<td>{{entry.id}}</td>
<td>{{entry.name}}</td>
</tr>
现在我想做这样的事情:
<tr ng-repeat="entry in entryList | myfilter1">
<td>{{entry.id}}</td>
<td>{{entry.name}}</td>
</tr>
<tr ng-repeat="entry in entryList | myfilter2">
<td>{{entry.id}}</td>
<td>{{entry.name}}</td>
</tr>
<tr ng-repeat="entry in entryList | myfilter3">
<td>{{entry.id}}</td>
<td>{{entry.name}}</td>
</tr>
迭代过滤器有什么好方法吗?
修改
这是link on sample。基本上,我正在寻找像ng-repeat="myfilter in [myfilter1, myfilter2, myfilter3]
这样的东西(尝试直接没有成功 - link)
答案 0 :(得分:1)
我相信你正在寻找这样的东西:
<span ng-repeat="fil in filters">
<tr ng-repeat="entry in entryList | filter: fil">
<td>{{entry.id}}</td>
<td>{{entry.name}}</td>
</tr>
</span>
在控制器上:
$scope.filters = [myfilter1, myfilter2, myfilter3];
注意:您可以使用其他元素标记代替<span>
如果您定义了自己的过滤器:
<table ng-repeat="fil in filters">
<tr ng-repeat="entry in fil(entryList)">
<td>{{entry.id}}</td>
<td>{{entry.name}}</td>
</tr>
</table>
在控制器上:
$scope.filters = [$filter('myfilter1'), $filter('myfilter2')];
<强> Demo 强>