html - How can i filter values in angularjs? -
hi how can filter values in angularjs?
i have created plunker reference :- my plunker.
i want filter
user
categories
in ng-repeatquestion list page
user datas:-
"user": { "_id": "58072aba0f82a61823c434df", "displayname": "table 1", "dob": "2016-12-22t18:30:00.000z", "location": "chennai", "religion": "hindu", "roles": [ "admin" ], "profileimageurl": "./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136" },
categories
values in array, need filtercategories
values in ng-repeat list page....for example:- if
user categories values
"categories": [ "religion & culture", "social psychology" ],
these 2 values should filter in list of category...
my html:-
<div ng-repeat="question in questions | filter:user.categories "> <small> <span >{{$index + 1}}.</span> <span data-ng-bind="question.category"></span> </small> </div>
i have used filter in ng-repeat :-
| filter:user.categories
i want filter user categories in repeat list...
please check , update plunker know exact solution...
you need create custom filter like:
.filter('filtercategory', [ function() { return function(questions) { var filteredcategories = []; if (questions && questions.length) { angular.foreach(questions, function(question) { console.log(question) if(question.user && question.user.categories && question.user.categories.length){ angular.foreach(question.user.categories, function(category){ if(filteredcategories.indexof(category)<0){ filteredcategories.push(category); } }) } }) } return filteredcategories; } } ])
and in ng-repeat need write:
<div ng-repeat="category in questions| filtercategory ">
Comments
Post a Comment