AngularJS Filter Exact Match
Solution 1:
This is now provided natively within the filter. You can just pass true to the filter to enable strict matching.
<li ng-repeat="movie in movieList | filter : filters : true">{{ movie.title }}</li>
Refereces
https://docs.angularjs.org/api/ng/filter/filter
https://stackoverflow.com/a/18243147/1466430
Solution 2:
In case someone wants to use the filter on the JavaScript side you can do it like:
$scope.filtered = $filter('filter')($scope.movieList, { genre.name: filters.genre}, true);
Notice the true at the end... it indicates that is to search for the exact match.
Solution 3:
filter
can also take a function where you can implement your own filter. I made a plunker showing it in action: http://plnkr.co/edit/v0uzGS?p=preview
Here's the relevant code:
$scope.ChooseGenreFunction = function(genre) {
$scope.filters = function(movie) {
return movie.genre === genre;
};
};
$scope.ChooseGenreString = function(genre) {
$scope.filters = genre;
};