Rohit Ghotkar Rohit Ghotkar - 1 month ago 19
AngularJS Question

ng-if condition in ng-repeat angular js

i want to put condition in ng-repeat as :
my code is

<tr ng-repeat='orders in allCurrentTakeAwayOrder' >

</tr>


but i want to put condition if heading is Take Away then ng-repeat shoul take values from allCurrentTakeAwayOrder if its Home Delivery then from allcurrentHMOrder as:

<tr ng-repeat='orders in allCurrentTakeAwayOrder if heading=Take Away or
orders in allcurrentHMOrder if heading=Home Delivery' >
</tr>

Answer

If you really want to use a condition inside your ng-repeat, I would suggest using a ternary operator, like this:

<input type="checkbox" name="condition" ng-model="condition" />
<ul ng-init="numbers=[1,2,3];letters=['a','b','c'];">
  <li ng-repeat="i in (condition ? numbers : letters)">
    {{i}}
  </li>
</ul>