I want to check the state of a property (true or false), on each object to determine weather or not to display a div.
For example, the following works great. Show "Student" heading if students.length > 0, then greet each student by name individually.
<div ng-if="ctrl.classroomInfo.students.length > 0">
<h1>Students</h1>
<ul>
<li ng-repeat="student in ctrl.classroomInfo.students">
Welcome, {{student}}!
</li>
</ul>
</div>
But what if I wanted to add another condition? I only want to show this classroomInfo <div> if atleast one student has good grades.
<div ng-if="ctrl.classroomInfo.students.length > 0 &&
ctrl.classroomInfo.students[$index].hasGoodGrades === true">
<h1>Students</h1>
<ul>
<li ng-repeat="student in ctrl.classroomInfo.students">
Welcome, {{student}}!
</li>
</ul>
</div>
In the above code block I have added students[$index].hasGoodGrades === true, but $index only works in combination with ng-repeat. Meaning I would need to add:
ng-repeat="student in ctrl.classroomInfo.students" to my div tag. This is bad because it will repeat the <h1>Students</h1> header for each student with good grades.
How can I access the hasGoodGrades property on each student object to determine weather or not to show this entire div?
UPDATE:
Thanks for the answers regarding filters. How do I handle a case where the filtered property is another level deep? For example:
ctrl.classroomInfo.students.RESULTS.hasGoodGrades
ng-if="(ctrl.classroomInfo.students | filter:{RESULTS.hasGoodGrades:true}).length > 0" doesn't work
lifor each student. It doesn't make any sense to put it where you've put it, as that's outside the loop.filter:{ RESULTS: { hasGoodGrades:true }}src - stackoverflow.com/a/32994920/1121919