Angular Ngclass with Ternary Operator Example
Hi,
Today, ngclass with ternary operator in angular is our main topic. if you have question about angular ngclass ternary operator then i will give simple example with solution. you will learn ternary operator ngclass angular 12. This article goes in detailed on angular 12 ngclass ternary operator. Let's get started with angular ngclass with ternary operator.
I will give you simple example of how to use ternary operator with ngclass in angular. you can use this example with in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17 version app.
Let's see bellow example:
app.component.html
<h1>angular ngclass ternary operator</h1>
<button [ngClass]="status == 'Active' ? 'active-class' : 'inactive-class'">Button</button>
app.component.ts
import { Component, VERSION } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular ' + VERSION.major;
status = 'Active';
}
app.component.css
.active-class {
color: green;
}
.inactive-class {
color: red;
}
Ouput:
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Index of Ngfor in Angular?
- Angular Check ngIf Null or Empty | Angular Check If Array is Empty
- Angular NgForm Example | NgForm Directive In Angular
- Angular NgModel Example | NgModel Directive In Angular
- Angular NgStyle Example | NgStyle Directive In Angular
- Angular NgClass Example | NgClass Directive In Angular
- Angular NgSwitch Example | NgSwitch Directive In Angular
- Angular NgIf Example | NgIf Directive In Angular
- Angular NgFor Example | NgFor Directive In Angular
- Angular NgIf Else | Ng If Else in Angular Example
- Angular Ng-Container Example Tutorial
- Angular Ng-Content Example Tutorial