How to maintain a "checked" checkbox after filtering

Asked

Viewed 101 times

0

<div ng-repeat="post in posts | filter:{components:component} | filter:{classification:class}:true">
     <ul>
          <div class="selected-{{'{{charter.selected}}'}}" ng-hide="post.charters.length <= 0" ng-repeat="charter in post.charters">
               <input type="checkbox" ng-model="charter.selected" ng-change="addSelectedCharters(post, charter)">
                    {{'{{charter}}'}}
          </div>
     </ul>
</div>

When I filter, all checkboxes that were previously checked are no longer. How can I resolve them? Thanks!

1 answer

0

I suggest you create a property in your items, which could be:

<div ng-repeat="post in posts | filter:{components:component} | filter:{classification:class}:true">
     <ul>
          <div class="selected-{{'{{charter.selected}}'}}" ng-hide="post.charters.length <= 0" ng-repeat="charter in post.charters">
               <input type="checkbox" ng-model="post.selected" ng-change="addSelectedCharters(post, charter)">
                    {{'{{charter}}'}}
          </div>
     </ul>
</div>

The difference is here ng-model="post.selected".

  • I appreciate your tip, but actually it’s the charters that have the checkbox each and not the post. Each post contains several charters. I want to select several charters, and when filter keep the charters of the other posts still selected, even if they do not appear after filtering. Did you understand better? Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.