1

i have this 2 loops

    <ion-list>
      <ion-item ng-repeat="category in categories" href="#">
        {{category.name}} {{category.id}}
          <ion-item ng-repeat="test in tests" href="#">
              {{test.name}} {{test.cat_id}}
          </ion-item>
      </ion-item>
    </ion-list>

i want to test if(category.id === test.cat_id) then show the second list

i'm not sure if and how to use ngif, or if i should take care of this in the controller and return one object already formatted for my needs..

any ideas?

1
  • 1
    Maybe <ion-item ng-repeat="test in tests" href="#" ng-show="category.id === test.cat_id"> ? Commented Apr 25, 2014 at 21:57

2 Answers 2

2

If I understand correctly you want to conditionally show the second ng-repeat. If that is the case then you can use this:

<ion-list>
  <ion-item ng-repeat="category in categories" href="#">
    {{category.name}} {{category.id}}
      <ion-item ng-repeat="test in tests" href="#" ng-if="category.id === test.cat_id">
          {{test.name}} {{test.cat_id}}
      </ion-item>
  </ion-item>
</ion-list>

Another option would be to use a filter like this:

<ion-list>
  <ion-item ng-repeat="category in categories" href="#">
    {{category.name}} {{category.id}}
      <ion-item ng-repeat="test in tests | filter: {cat_id: category.id}" href="#" ng-if="category.id === test.cat_id">
          {{test.name}} {{test.cat_id}}
      </ion-item>
  </ion-item>
</ion-list>

I would actually recommend the filter option.

Sign up to request clarification or add additional context in comments.

Comments

0

What about something like this?

<ion-list>
  <ion-item ng-repeat="category in categories" href="#">
    {{category.name}} {{category.id}}
      <ion-item ng-repeat="test in tests | filter:{cat_id: category.id}" href="#">
          {{test.name}} {{test.cat_id}}
      </ion-item>
  </ion-item>
</ion-list>

Comments

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.