Thunfische
Thunfische

Reputation: 1157

Angularjs showing a string if the object is null in an html table

<td ng-repeat="course in student.extracourses">
    <div ng-if="!course">  not selected   </div>
    {{b.note}}
</td>

I have a table with some static columns and dynamic columns with respect to student extracourses. Some students do have extra notes and some do not. How can I show in the table 'not selected' if the 'course' does not exist? I tried this code above and it did not print 'not selected' for those who do not have a course

Upvotes: 0

Views: 34

Answers (1)

Obsidian Age
Obsidian Age

Reputation: 42304

You can use <div ng-if="course === undefined"> to check whether course is set or not:

<td ng-repeat="course in student.extracourses">
  <div ng-if="course === undefined">not selected</div>
  {{b.note}}
</td>

Or alternatively, check the typeof():

typeof(course) === "undefined"

Upvotes: 1

Related Questions