Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add | remove css class in angular element?

Tags:

css

angular

How to add | remove css class in angular element?

Access to angular element is via: this.elementRef.nativeElement (import { ElementRef } from '@angular/core';). CSS class name is myclass.

like image 864
Sergii Avatar asked Mar 25 '26 10:03

Sergii


1 Answers

constructor(public elementRef: ElementRef, private renderer: Renderer)
{
        this.renderer.setElementClass(this.elementRef, 'class');
   // or 

            this.elementRef.nativeElement.classList.add('class');

}
  1. Using Renderer
  2. Using addClass on Native element
like image 155
Subtain Ishfaq Avatar answered Mar 27 '26 03:03

Subtain Ishfaq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!