Rohit Ghotkar Rohit Ghotkar - 1 year ago 138
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' >


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' >

Answer Source

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)">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download