How to filter multiple values (OR operation) in angularJS

前端 未结 20 1273
清酒与你
清酒与你 2020-11-22 10:01

I want to use the filter in angular and want to filter for multiple values, if it has either one of the values then it should be displayed.

I have for

20条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 10:22

    You can use a controller function to filter.

    function MoviesCtrl($scope) {
    
        $scope.movies = [{name:'Shrek', genre:'Comedy'},
                         {name:'Die Hard', genre:'Action'},
                         {name:'The Godfather', genre:'Drama'}];
    
        $scope.selectedGenres = ['Action','Drama'];
    
        $scope.filterByGenres = function(movie) {
            return ($scope.selectedGenres.indexOf(movie.genre) !== -1);
        };
    
    }
    

    HTML:

    • {{ movie.name }} {{ movie.genre }}

提交回复
热议问题