Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda