I need to filter a list of items by their category. I want the user to be able to click a button, and then have the filter applied to a list.
At the moment, I have t
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
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.
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;
};