N
N
Nikita Baev2015-06-02 09:06:01
JavaScript
Nikita Baev, 2015-06-02 09:06:01

How to make multiple filters in Angular?

There was a need to make multiple data filtering in Angular. Tried several different ways, but almost all had their drawbacks. In particular: filtering by one value is mainly offered, but I have a lot of them.
There are objects with the following structure:

[
  {
    "id": 1,
    "name": "Артист",
    "state": "Не женат",
    "price": 50000,
    "bio": "Офигенный артист",
    "genre": {
      "id": 1,
      "name": "Тамада"
    },
    "country": {
      "id": 1,
      "name": "Россия"
    },
    "type": {
      "id": 1,
      "name": "Тип1"
    }
  }
]

There is a menu in which all types from the database are displayed and ng-click, on which the filter object is pushed:
{
  "id": 1,
  "name": "Тип1"
}

And then ng-repeat should display items by filter:
<section class="artist-item" ng-repeat='artist in Filters = (artists | filter:typeFilters | filter:searchText)'></section>

But they don't come out.
Has anyone encountered this problem or seen a solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-06-02
@drugoi

or saw the solution

Do filtering in the controller in any way convenient for you. Stop writing logic in templates.

A
Alexander Tartmin, 2015-06-02
@baskerville42

And well, throw the whole code, it seems to me that you are not calling the filters correctly on the presentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question