#

Sunny Kushwaha

Admin

Angular ngClass Example

In Angular, ngClass is a directive that allows you to set CSS classes dynamically based on conditions or variables in your component.
Here's an example:

ngClass Basic Example
                                    
                                        <button [ngCtyle]="active-button">
                                            Example Button
                                        </button>
                                    
                                
ngClass Example With Ternary Operator
                                    
                                        <button [ngClass]="isActive ? 'active-button' : 'inactive-button'">
                                            <!-- isActive (can be set from component ts file) can be true or false -->
                                        </button>
                                    
                                
ngClass Example With Multiple Conditions
                                    
                                        <button [ngStyle]="isFirst || isSecond ?  'active-button' : 'inactive-button'">
                                            <!-- isFirst or isSecond (can be set from component ts file) can be true or false -->
                                        </button>
                                    
                                
That's all you need to implement ngClass, my friend!
  • Please refer to the below links for details: