如何使用ng-if限制ng-repeat [英] How to restrict ng-repeat with ng-if

查看:88
本文介绍了如何使用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.

JSFiddle

推荐答案

您可以在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 }"

这篇关于如何使用ng-if限制ng-repeat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆