如何使用ng-if限制ng-repeat
问题描述:
<div ng-repeat="post in posts" ng-if="post.type !='article'">
<h1>{{post.title}}</h1>
</div>
在上面的代码中,
仅在'artical'出现时才会受到限制,但是在我的场景中我将下拉列表进行动态添加.在这里我想限制已经选择的值不应在其中可见下一个添加的下拉菜单.
in the above code that will restrict only when 'artical' comes to the list then it will restrict.but In my scenario I have drop down that will add dynamically.Here I want to restrict already selected value should not be visible in the next added drop down.
答
您可以在ng-repeat
集合上使用filter
,然后在其中动态传递type
值.
You could use filter
on ng-repeat
collection, and pass type
value dynamically there.
ng-repeat="post in posts | filter: { type: selectedValue }"