Quantcast
Viewing all articles
Browse latest Browse all 26

Answer by Jameel Moideen for Angular: conditional class with *ngClass

You can use ngClass to apply the class name both conditionally and not in Angular

For Example

[ngClass]="'someClass'">

Conditional

[ngClass]="{'someClass': property1.isValid}">

Multiple Condition

 [ngClass]="{'someClass': property1.isValid && property2.isValid}">

Method expression

[ngClass]="getSomeClass()"

This method will inside of your component

 getSomeClass(){        const isValid=this.property1 && this.property2;        return {someClass1:isValid , someClass2:isValid};    }

Viewing all articles
Browse latest Browse all 26

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>