I have list of objects with various properties. And list of objects that I should use as a filter.
$scope.filters = [
{ title: "title1", options: [
{ text: "all", tags: ["1","2","3"] },
{ text: "1", tags: ["1"] },
{ text: "2", tags: ["2"] },
{ text: "3", tags: ["3"] }
]
},
{ title: "title2", options: [
{ text: "all", tags: ["a","b","c"] },
{ text: "a", tags: ["a"] },
{ text: "b", tags: ["b"] },
{ text: "c", tags: ["c"] }
]
}]
$scope.products = [
{ name: "foo", tags: ["1", "a","main"] },
{ name: "bar", tags: ["2", "b", "second"] },
{ name: "baz", tags: ["1", "c", "second"] },
{ name: "tap", tags: ["3", "c", "main"] }
]
I displayed filters as select elements.
<div ng-repeat="filter in filters">
<label for="filter">{{::filter.title}}</label>
<select name="filter" ng-options="choice as choice.text for choice in filter.options track by choise.tags"></select>
</div>
But how do I use filter here? http://plnkr.co/edit/S18xKkXPieWEBvMD3FqJ?p=preview
To make selected option available in main controller I can write ng-model="$parent.selectedOption"
but it will be rewrited if any other select is changed and I'm not sure is that a right thing to tamper parent scope like so.
EDIT:
I want to filter products using a set of filters(defined via select).
For example:
select1 = "2"
select2 = "b"
Then filtered products should contain only those where tags
property include that values from selects