Filtering response exactly and not by similarity


#1

hallo
in my API I present a parent list of categories and then I filter the product list by the chosen category.
This is my asset:
response JSON:
[
{ “name”: “prod1”, “category_id”: “17” },
{ “name”: “prod2”, “category_id”: “7” }
]

**categories template:**
<ion-list>
      <a ng-repeat="categ in categs" href="#/tab/categories/{{categ.id}}">
      	<h2>{{ categ.name }}</h2>
      </a>
    </ion-list>

**product list controller:**
.controller('ProductsCtrl', function($scope, HttpService, $filter, $stateParams) {
  HttpService.all()
    .then(function(response) {
      var category=$filter('filter')(response.products, { category_id: $stateParams.categ_id });
      $scope.products=category;
    });
})

I am getting a weird behaviour:

  1. when I choose the category “17”, I get only the product “prod1” and that’s right
  2. when I choose the category “7” I get both “prod2” and “prod1”, since “prod1”'s category_id CONTAINS "7"
    How could I address this?
    Thanks in advance

#2

Actually it was quite a rookie question…

I (partially) solved by using this syntax:
var category=$filter(‘filter’)(response.products, { category_id: $stateParams.categ_id }, true);