texas697
texas697

Reputation: 6387

How to display nested objects with ng-repeat

I have a table displaying my Users. A user can be assigned to muptiple companies. I need to display that in the table. I have seen some similar posts that reference some tree directives. They appear to be more complex than what I need. I created a plunker. Plunker

 <table class="table table-bordered">
  <thead>
    <tr>
      <th>Company(s) Name</th>
      <th>Name</th>
      <th>UserName</th>
      <th>Email</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="user in users | filter:search">
      <td>{{user.Companies.CompanyName}}</td>
      <td>{{user.Name}}</td>
      <td>{{user.UserName}}</td>
      <td>{{user.Email}}</td>
    </tr>
  </tbody>
</table>

Upvotes: 0

Views: 35

Answers (1)

vitalik_74
vitalik_74

Reputation: 4591

Try that

<tr ng-repeat="user in users | filter:search">
  <td>
    <font ng-repeat="company in user.Companies">{{company.CompanyName}}{{$last?'': ','}} </font>
    </td>
  <td>{{user.Name}}</td>
  <td>{{user.UserName}}</td>
  <td>{{user.Email}}</td>
</tr>

See in plunker

Upvotes: 1

Related Questions