Angular.js Ng-repeat Filter By Property Having One Of Multiple Values (OR Of Values)


Answer :

Best way to do this is to use a function:

<div ng-repeat="product in products | filter: myFilter">  $scope.myFilter = function (item) {      return item === 'red' || item === 'blue';  }; 

Alternatively, you can use ngHide or ngShow to dynamically show and hide elements based on a certain criteria.


For me, it worked as given below:

<div ng-repeat="product in products | filter: { color: 'red'||'blue' }">  <div ng-repeat="product in products | filter: { color: 'red'} | filter: { color:'blue' }"> 

I thing ng-if should work:

<div ng-repeat="product in products" ng-if="product.color === 'red'  || product.color === 'blue'"> 

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android SDK Location Should Not Contain Whitespace, As This Cause Problems With NDK Tools