Is there a way to replace a class using renderer2 in angular

845 Views Asked by At

I am using angular 10 and using Renderer2 to add and remove classes:

this.renderer.removeClass(this.document.body, 'signin-user');
this.renderer.addClass(this.document.body, 'anonymous-user');

Does Renderer2 let me replace a class. For e.g if "signin-user" is applied replace it with "anonymous-user" and vice-versa instead of writing the removeClass function.

1

There are 1 best solutions below

0
On
this.renderer2.addClass(element, 'className');
this.renderer2.removeClass(element, 'className');

You can check this out here