1

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.

2
  • 1
    No, there isn't a method to do directly via Renderer2. You can write a common method to do that, of course. Commented Mar 7, 2022 at 9:52
  • No, you can't, it's straight forward though. Commented Mar 7, 2022 at 9:53

1 Answer 1

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

You can check this out here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.