I have a situation in my Angular 2 app where I am iterating over an array of objects, and if the "completed" property is set to false
for any of those objects, I want to print to the view 'Yes', because there is (at least) one object with "completed" equal to false
-- meaning it's still an active flag.
However, right now, the template code I have is printing 'Yes' to the view for EACH time one of these objects with the "completed" property set to false
returns true
. How can I adjust this code so that I'm only getting "Yes" printed once if ANY ONE (or more) of the objects in the array being iterated over has that "completed" property set to true?
Here's my code:
<td *ngFor="let flag of service.flags">
<ng-template *ngIf="flag?.completed === false">
<span class="standard-flag">Yes</span>
</ng-template>
</td>
I also tried using the ternary operator, but it gives me the same result:
<td *ngFor="let flag of service.flags">
<ng-template *ngIf="flag?.completed === false ? true : false"">
<span class="standard-flag">Yes</span>
</ng-template>
</td>
While I would normally handle the logic in the component, I'm thinking there must be a way, perhaps with indexing, that I could this in the view on this occasion.
Yes
`. – Reticulated Spline Jul 27 '17 at 22:14