1

I have this template where I am displaying data in tables:

<tr ng-repeat="obj in tsc.tabEntries" ng-class-odd="'odd'" ng-class-even="'even'">
  <td ng-repeat="field in tsc.entryFields">{{ obj[field]}}</td>
</tr>

I want to check that obj[field] is an object. If it is, I want to display the name property of that object, otherwise the value of obj[field].

How can I do that in template?

Badacadabra
  • 8,043
  • 7
  • 28
  • 49
user3214546
  • 6,523
  • 13
  • 51
  • 98

2 Answers2

3

Try

<td ng-repeat="field in tsc.entryFields">{{ obj[field].name || obj[field] }}</td>

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

You can try ng-show for this type of logic in template

  <tr ng-repeat="obj in tsc.tabEntries" ng-class-odd="'odd'" ng-class-even="'even'">
    <span ng-show="obj.field.name">{{obj.field.name}}</span>
    <td ng-repeat="field in tsc.entryFields">{{ obj[field]}}</td>
</tr>
Saqueib
  • 3,484
  • 3
  • 33
  • 56