Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
Angular2 renderer setElementClass isAdd options does not work

Why doesn't this work, as stated in the docs ?

renderer.setElementClass(el, 'class1', false); // replace class
renderer.setElementClass(el, 'class2', true); // add a class

This results in the element only have the class2 instead of both.

Reference Angular2 renderer docs

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Just to mention that Renderer is deprecated now, and have been replaced by Renderer2. In the Renderer2 class there are two methods that replace the setElementClass of the deprecated Renderer.

  • To add a class:

    renderer.addClass(this.elementRef.nativeElement, 'popup');

  • To remove a class:

    renderer.removeClass(this.elementRef.nativeElement, 'popup');

For more information see: https://angular.io/api/core/Renderer2

For code samples in form of tutorial see: https://alligator.io/angular/using-renderer2/ in particular the section of 'addClass / removeClass'

about 4 years ago · Santiago Trujillo Report

0

It turns out the isAdd option is the equivalent of a remove class, so the following works for toggling classes:

renderer.setElementClass(el, 'class1', false); // remove class1
renderer.setElementClass(el, 'class2', true); // add class2

Oh, nothing strange about calling a method setElementClass for removing it of course...

about 4 years ago · Santiago Trujillo Report

0

Renderer class has been removed in version 9 and migrated it to Renderer2

In Renderer -> setElementClass(renderElement, className, isAdd)

In Renderer2 -> isAdd ? addClass(renderElement, className) : removeClass(renderElement, className)

In short setElementClass method has been migrated into addClass method and removeClass method based on the third parameter passed in setElementClass.

  • If third parameter is true -> method will be addClass
  • If third parameter is false -> method will be removeClass
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!