Loading…

How to write If Else and Then Conditions in Angular 4?

If Else statement in Angular 4 can be written using following syntax-
Open /src/app/app.components.ts:
Export class AppComponent {
Title – ‘app works!;
}

Open /src/app/app.component.html
<div *ngIf = “ title; else login”>
The user is logged in. </div>
<ng-template #login> in order to login pleae continue. </ng-template>
Then statement can be write using following syntax-
<div *ngIf = “title; then logout else login “> </div>
<ng-template #login> please login to continue . </ng-template>
<ng-template #logout> Hi abc, <button> logout now </button> . </ng-template>

Suggest An Answer

No suggestions avaliable!

Latest post from Angular 4 Interview Questions

Ask Question