4

I'm trying to something like

<ion-item class="item-icon-right " ng-repeat="project in jsonObj.Projects | filter:projectArea:true:ProjectStatus" type="item-text-wrap" ui-sref="tabs.detail({project:project['Project name']})">
  <div class="row">
    <div class="col col-45">
      <h2>{{project["Project name"]}}</h2>
      <h4>{{project["PM"]}}</h4>
    </div>

    <div class="col col-45"></div>
    <div class="col col-10">
      <span class="badge badge-assertive icon-badge"><i class="ion-ios-arrow-right"></i></span>
    </div>
  </div>
</ion-item>

Controller:

angular.module('App')
 .controller('ProjectsController', function ($scope, $rootScope, $stateParams, $state) {
        $scope.projectArea = $stateParams.area;
        $scope.ProjectStatus = $stateParams.Project_Status;      
  });

Data:

{PM: "Oommen", Area: "Foods", Project name: "PLuM", Reviewer: "Alex", A&D Start Date: "7-Dec-15"…}$$hashKey: "object:31"A&D End Date: "15-Jan-16"A&D Start Date: "7-Dec-15"Area: "Foods"Build End Date: "TBD"Build Start Date: "TBD"Implementation date: "TBD"PM: "Oommen"Project Status: "Green"Project name: "PLuM"Reviewer: "Alex"SIT End Date: "TBD"SIT Start Date: "TBD"ST End Date: "TBD"ST Start Date: "TBD"Status: "HLD Phase Kickoff. Review to be planned early"}

I'm trying filter ng-repeat with Area and Project Status values. However it filters only based on Area. Could you someone help to identify the problem?

4
  • 1
    Cascade filters? project in jsonObj.Projects | filter:projectArea:true | filter:ProjectStatus Commented Jan 5, 2016 at 13:08
  • You can also pass the object to filter: arrayOfObjects | filter:{Area: xxx, ProjectStatus: kkk} Commented Jan 5, 2016 at 13:11
  • @JohannesJander its working thank you. Please write it as answer, so that i can accept it. Commented Jan 5, 2016 at 13:13
  • @Ram great :) I have made the comment into an answer with a link, so please accept it. Commented Jan 5, 2016 at 13:17

2 Answers 2

1

You can chain filters:

 project in jsonObj.Projects | filter:projectArea:true | filter:ProjectStatus
Sign up to request clarification or add additional context in comments.

Comments

0

Two options:

  1. Use multiple filters where one filter uses the result of the previous filter (chaining)

    ng-repeat="project in projects | myFirstFilter | mySecondFilter"

  2. Pass on the data or object you want to add to the equation to the filter.

    ng-repeat="project in projects | myFirstFilter:myData"

I'd go with the first option because it creates a clear separation of what each filter does. Makes it easier to test as well.

1 Comment

Why the first option if I may ask?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.