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
  • 5,771
  • 7
  • 27
  • 45
user3214546
  • 6,093
  • 12
  • 49
  • 94

2 Answers2

3

Try

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

Demo: Fiddle

Arun P Johny
  • 376,738
  • 64
  • 519
  • 520
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,452
  • 2
  • 30
  • 53