I want to filter results by id, or rating and various other keys, I'm using this data structure:
[
{
"id": "1"
"Description": "desc 1",
"Rating": "rating 1",
"MainImage": "image.jpg"
},
{
"id":"1"
"Description": "desc 2",
"Rating": "rating 2",
"MainImage": "image.jpg"
},
{
"id": "2"
"Description": "desc 3",
"Rating": "rating 3",
"MainImage": "image.jpg"
}
]
This data is returned from a promise and is assigned to $scope.results
. In the template there is an ng-repeat
to iterate over the results. This is working fine, my question is:
How do I filter the results by id
so for example only the results with the id
of 1 are displayed? I had this working but it wasn't the most efficient. I reassigned the filtered results back to $scope.results
which did work but then the entire data structure had been replaced by the one containing the filtered results. That obviously wasn't going to work and I did a work around but I know this isn't the best way.
I need a custom filter that will be able to handle filtering using 3 different select lists so for example a rating
select list, a productId
and a productName
.
How exactly would I write this function?
<div class="product" data-ng-repeat="product in products | filter:searchFilter"></div>