Search code examples
javascriptarraysangularjsangular-filters

AngularJS - Array as filter


How can I setup a filter in an ng-repeat that use strings and an array of strings?

HTML

<div ng-repeat="type in types| orderBy : 'name' | filter:{typology:currTipology}"

JavaScript

var myData = ['string_1', 'string_2', ['string_3', 'string_4']];

I'll use a button for every myData entry to assign the string value to ´currTipology`.

UPDATE I try to better explain my issue. I have a main object data with 6 different 'typology' properties. I need to place 4 buttons: button 1 to 3 corresponds to 1 to 3 'typology' properties; the last button has to filter the 4 to 6 'typology' properties. How should i use filters for last button?


Solution

  • For multiple filter you can do with function some thing like this

    <div ng-repeat="employee in employees | filter:{name: companyName} | filter:gradeFilter">
    

    And in controller you have your filter function some thing like

    $scope.gradeFilter = function (employee) {
       if(employee.salary > 70000 && employee.exp > 3){ 
          return "Senior"
       } 
    }