JS corner expression in ng-repeat

I would like to know what is the most elegant and easiest way to implement this. I need to add a filter expression for ng-repeat that will filter 2 conditions from one property.

In this example, http://plnkr.co/edit/OMQxXvSjtuudMRGE4eZ8?p=preview

  • If you enter A, a check box for A is displayed.
  • check B - display for B.

But I want to show the indicated flags plus something with an empty condition. There is no condition for C, therefore:

  • if you enter A, I want to display flags A and C,
  • enter B, I want to display both flags B and C.
+4
source share
4 answers

, :

app.filter('myfilter', function() {
   return function( items, condition) {
    var filtered = [];

    if(condition === undefined || condition === ''){
      return items;
    }

    angular.forEach(items, function(item) {          
       if(condition === item.condition ||  item.condition === ''){
         filtered.push(item);
       }
    });

    return filtered;
  };
});

:

<span ng-repeat="charge in charges  |  myfilter:level.condition">

. Plunker

.

,

+7

, :

$scope.filterExpression = function(charge) {
  return (!$scope.level || !charge.condition || 
          ($scope.level.condition.toUpperCase() === charge.condition.toUpperCase()));
}

:

<span ng-repeat="charge in charges | filter:filterExpression">

plunkr ()

+8

: data-ng-repeat = " | : searchText" data-ng-if = "filter = searchText.Name"

+3

ng- :

1st: , AND,

2nd: ,

-3

Source: https://habr.com/ru/post/1533235/


All Articles