Ponnusamy
Ponnusamy

Reputation: 11

How to put if else in ng-repeat statement

     <div ng-repeat="d in data" ng-if="data.length>0">                                                    
         <div ng-bind="d.aa"></div>
         <div ng-bind="d.bb"></div>        
         <div ng-if="d.test == 'true'">
           <div ng-bind="it's test" />
           </div>    
         </div>
     </div>

Content:

  1. I need to display d.test= true means , it's test like.
  2. Normally ng-if is working fine, with in ng-repeat and ng-bind it does not work.

Please help this

Upvotes: 1

Views: 3443

Answers (1)

dheeraj Kumar
dheeraj Kumar

Reputation: 372

<div ng-repeat = "data in comments">
    <div ng-if="data.length >0">
        //different template with 0 data
    </div>
    <div ng-if="data.type == 'story' ">
        //different template with story data
    </div>
    <div ng-if="data.type == 'article' ">
        //different template with article data
    </div> 
</div>

you can use also

<li ng-repeat="r in results">
  <!-- If r.date contains a value, show it -->
  <span ng-if="r.date">{{r.date}}</span>
  <!-- If r.date does not contain a value show placeholder text -->
  <span ng-if="!r.date">Date not confirmed yet.<span>
</li>

Upvotes: 4

Related Questions