javascript - Angular Checkbox Filter with Paginator -


i'm using angularjs paginator, https://github.com/michaelbromley/angularutils/tree/master/src/directives/pagination. , i'm using example in this video add checkbox filters ng-repeat. want filter based on whether specie property of every animal object (animal.specie) cat or dog. start setting both true ng-repeat doesn't populate when that. , when check box true or false nothing happens.

the thing in controller $scope.species = {dogs: true, cats: true};

what wrong implementation? appreciated.

thanks :)

    <div class="row adopt-title-wrap">     <div class="medium-6 large-6 column">         <h3>find next best friend</h3>     </div>     <div class="medium-2 large-2 end column">         <input type="checkbox" ng-model="species.cats">         <label>cats only</label>     </div>     <div class="medium-2 large-2 end column">         <input type="checkbox" ng-model="species.dogs">         <label>dogs only</label>     </div> </div><br>  <i class="fa fa-spinner fa-pulse fa-3x"></i>  <div class="row">     <!-- start single animal record -->     <div class="medium-6 large-6 end column" dir-paginate="animal in animals                                                         | filter: {specie: 'dog'} : species.dogs                                                         | filter: {specie: 'cat'} : species.cats                                                         | itemsperpage: 6">         <div class="panel">             <img class="pet-img" ng-src="{{ animal.profile_photo }}" alt="pet adoption">             <ul class="pet-details">                 <li class="pet-field-title">name</li>                 <li class="pet-field-value">{{ animal.name }}</li>                 <li class="pet-field-title">age</li>                 <li class="pet-field-value">{{ animal.dob }}</li>                 <li class="pet-field-title">breed</li>                 <li class="pet-field-value">{{ animal.breed }}</li>                 <li class="pet-field-title">code</li>                 <li class="pet-field-value">{{ animal.shelter_code }}</li>             </ul>             <p class="pet-description">{{ animal.description }}</p>         </div>     </div> <!-- end single animal record --> </div>  <dir-pagination-controls></dir-pagination-controls> 

i recommend stripping down code base, maybe displayed , migrate pagination. can spot first issue applying 2 filters on specie.

dir-paginate="animal in animals | filter: {specie: 'dog'} | filter: {specie: 'cat'}" 

is saying filter down animals both dog and cat. first filter return array of dogs, second filter run on finding cats, none because can't dog , cat :)

original array: [{name: 'bob', specie: 'cat'}, {name: 'jeff', specie: 'dog'}] | filter dogs | filter cats after first filter (only dogs): [{name: 'jeff', specie: 'dog'}] | filter cats  after second filter (only animals both dogs , cats): [] 

try defining own angular filter simplify work so:

.filter('iscatordog', function() {     return function(inputanimals) {        return inputanimals.filter(function(animal) {           return animal.value === 'cat' || animal.value === 'dog';        });     } }); 

and call filter so:

dir-paginate="animal in animals | iscatordog" 

basic plunkr


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -