Web / Angular Interview questions
How does *ngIf directive works?
ngIf directive does not show or hide an element from DOM. Instead, the ngIf directive removes or recreates a portion of the DOM tree based on the ngIf {expression}. If the expression assigned to ngIf evaluates to a false value then the element is removed from the DOM, otherwise, a clone of the element is reinserted into the DOM.
Angular translates the *ngIf attribute into a <ng-template> element, wrapped around the host element. For example, consider the below code snippet.
<div *ngIf="employee" >{{employee.name}}</div>
This code will be translated as shown below by Angular.
<ng-template [ngIf]="employee"> <div>{{employee.name}}</div> </ng-template>
More Related questions...