Skip to main content

angular - Multiple condition

app.component.ts

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

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

export class AppComponent {
  textColor: String = "blue";
}
app.component.html

<h2>Angular Multiple Condition</h2>

<ng-template [ngIf] = "textColor == 'red'">
    <h3 style="color: red;">Red color</h3>
</ng-template>

<ng-template [ngIf] = "textColor == 'green'">
    <h3 style="color: green;">Green color</h3>
</ng-template>

<ng-template [ngIf] = "textColor == 'blue'">
    <h3 style="color: blue;">Blue color</h3>
</ng-template>

<ng-template [ngIf] = "textColor == 'yellow'">
    <h3 style="color: yellow;">Yellow color</h3>
</ng-template>
More Angular tutorials