AngularJS根据范围值过滤ng-repeat

时间:2014-12-28 23:31:18

标签: javascript angularjs

我想显示书签值设置为1的所有数据(联系人)

为此,我使用了这段代码:

<ul class="span5">
        <li class="nav-pills nav-stacked contact-row" data-ng-repeat="contact in contacts | orderBy:'firstName'" ng-show="contact.bookmarked('0')">
            <span id=" ct-details-{{contact.id}}" data-ng-click="displayContact(contact.id)" style="cursor:pointer;" class="contact-data details-hidden" href="">
                <span class="span3 contact-name">
                    {{contact.firstname + ' ' + contact.lastname}}
                </span>
            </span>
            <button class="btn editContact" id="deleteContact-{{contact.id}}" data-ng-click="deleteContact(contact.id)">Delete</button>
            <button class="btn editContact" id="editContact-{{contact.id}}" data-ng-click="editContact(contact.id)">Edit</button>
        </li>
    </ul>

当我使用此代码时,不显示联系人(值1的值和值0的值不显示)。有人知道问题在哪里以及如何解决它?

1 个答案:

答案 0 :(得分:2)

您应该在ngRepeat查询中创建过滤器。

 data-ng-repeat="contact in contacts | filter:{bookmarked:'0'} | orderBy:'firstName'"

详细了解此处:https://docs.angularjs.org/api/ng/filter/filter