简体   繁体   中英

AngularJS filter ng-repeat based on value from scope

I want to display all data (contacts) that have bookmarked value set to 1

To do that I used this peace of code:

<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>

When I use this code, contacts are not displayed (ones with value 1 and ones with value 0 are not displayed). Does someone knows where's the problem and how to fix it?

You should create a filter on your ngRepeat query.

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

Read more about here: https://docs.angularjs.org/api/ng/filter/filter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM