Lakmi
Lakmi

Reputation: 1389

How to filter inner array in json using $filter angular js

I want to filter json inner array

this is my array

{
    "code": "project_create",
    "WFID": ["1, "5", "2", "8", "9", "10", "7"]
 },
 {
   "code": "Task_create",
   "WFID": ["1", "5", "2", "8", "9"]
 },
 {
   "code": "project_update",
   "WFID": ["10", "5", "2", "8", "9"]
 },

I want to filter by WFID=1

I try this way

var saveWorkflowobj = $filter('filter')(tiggers.alltigger, { WFID: WorkFlowID});

Upvotes: 0

Views: 144

Answers (1)

Slava Utesinov
Slava Utesinov

Reputation: 13488

angular.module('app', []).controller('ctrl', ['$scope', '$filter', function($scope, $filter) {
    $scope.items = [
       {
          "code": "project_create",
          "WFID": ["1", "5", "2", "8", "9", "10", "7"]
       },
       {
         "code": "Task_create",
         "WFID": ["1", "5", "2", "8", "9"]
       },
       {
         "code": "project_update",
         "WFID": ["10", "5", "2", "8", "9"]
       }
    ];
 
    $scope.result = $filter('filter')($scope.items, {WFID : "1"}, function(a, b){
      return a === b;
    }); 
}])
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
 
 <div ng-app='app' ng-controller='ctrl'>   
   <ul>
     <li ng-repeat='item in result'>{{item | json}}</li>
   </ul>   
 </div>

Upvotes: 1

Related Questions