InterviewSolution
Saved Bookmarks
| 1. |
How would you use ngFor and ngIf together? |
|
Answer» NgFor and NgIf cannot be used TOGETHER on the same element. However, there is a WORKAROUND that allows you to ACHIEVE the results that you generally intend to get by using these two directives together. You can use an ng-container component. Look at the example code below. <some-component> <ng-container *ngFor="LET task of tasks"> <p *ngIf="task.Status == ‘done’">{{task.Title}}</p> </ng-container> </some-component> <ng-container>is a LOGICAL container that can be used to group nodes but is not rendered in the DOM tree as a node. <ng-container> is rendered as an HTML comment. |
|