AngularJS Filter Based On Array Of Strings?
I'm having a hard time wrapping my head around how to go about doing an Angular filter to solve a problem that I'm running into. Here's a basic example of my data structure, an arr
Solution 1:
You could write a custom filter. The filter would be given the list of active tags, tags
, and the array of tasks to be filtered, tasks
, and would output an array of filtered tags. It will be much the same as what you've already done, but with no extra function on the scope.
angular.module('myApp').filter('selectedTags', function() {
return function(tasks, tags) {
return tasks.filter(function(task) {
for (var i in task.Tags) {
if (tags.indexOf(task.Tags[i]) != -1) {
return true;
}
}
return false;
});
};
});
Then you can use it like
<ul>
<li ng-repeat="task in tasks | selectedTags:tags"></li>
</ul>
Check out this fiddle.
Post a Comment for "AngularJS Filter Based On Array Of Strings?"