Angular

How to use *ngIf else in Angular?

Pinterest LinkedIn Tumblr

1 )  If condition

<div *ngIf=”ifValid”>
ifValid is true
</div>

2) Using If with Else (Please notice to templateName)

<div *ngIf=”ifValid; else templateName”>
ifValid is true
</div>

<ng-template #templateName>
IfifValid is false
</ng-template>

3) Using If with Then (Please check templateName)

<div *ngIf=”ifValid; then templateName”>
Here is never showing
</div>

<ng-template #templateName>
IfifValid is true
</ng-template>

4) Using If with Then and Else

<div *ngIf=”ifValid; then thenTemplateName else elseTemplateName”>
This will never show
</div>

<ng-template #thenTemplateName>
ifValid is true
</ng-template>

<ng-template #elseTemplateName>
IfifValid is false
</ng-template>

 

 

Write A Comment