Skip to main content

angular - How to use then else condition

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  isError:boolean = true;
}
app.component.html

<h2>Angular Then Else Condition</h2>

<div *ngIf="isError then errorTemplate;else lorem_ipsum">
    This line will be ignore.
</div>

<ng-template #errorTemplate>
    This document has an error.
</ng-template>

<ng-template #lorem_ipsum>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Donec tincidunt est quam, nec hendrerit nisl laoreet laoreet.
</ng-template>
More Angular tutorials