Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

This might be simple but i am not sure how to go about it. I have created two scope array(not sure if required in controller) and my actual list in controller

$scope.tagFilter = [{tag_id:1,tag_name:test},{tag_id:2,tag_name:test2}];
$scope.categoryFilter = [{cat_id:1,cat_name:test3},{cat_id:2,cat_name:test4}]

my actual list

$scope.list = [{list_id:1,category_id:1,tag:1},...]

Is it possible to create a filter where i can compare tag_id with tag in list and cat_id with category_id I was thinking of creating angular.module.filter but not really sure how to do it

share|improve this question

1 Answer 1

You can write a filter function which behaves in the following way:

var allowed_tags = $scope.tagFilter.map(function(item){
    return item.tag_id;
})

var allowed_cat = $scope.categoryFilter.map(function(item){
    return item.cat_id;
})

var filtered = $scope.list.filter(function(i){
return ((allowed_tags.indexOf(i.tag) != -1) && 
        (allowed_cat.indexOf(i.category_id) != -1));
})

console.log(filtered);
share|improve this answer
    
i am very new to angularjs so this is kind of throwing me off. I understand what you are trying to do but can you please tell me how .map works,does it match item with tag_id with each object, and where exactly will i be placing this code. Does this go in controllers? – Asif Alamgir Nov 18 '14 at 19:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.