How to filter a list in AngularJS using several links

后端 未结 2 1582
一生所求
一生所求 2020-12-25 13:15

I have been going over a lot of tutorials on how to filter a list and can\'t find an example for my simple use-case.

I have several buttons such as

&         


        
2条回答
  •  盖世英雄少女心
    2020-12-25 14:02

    You can bind your filter to scope variables as you do with any other thing. So all you need is to set the appropriated filter to the scope when the user click and bind it to the ng-repeat filter param. See:

    Type 1 | Type 2 | No filter
    • {{person.name}}
    function Test($scope) {
      $scope.persons = [{type: 1, name: 'Caio'}, {type:2, name: 'Ary'}, {type:1, name: 'Camila'}];
    }
    

    Notice that the myFilter is changed when the user clicks the filter, and that it's bound to the ng-repeat filter. Fiddle here. You could also create a new filter, but this solution is far better.

提交回复
热议问题