Angular2 parameter rendererElementClass isAdd not working

Why does this not work as indicated in the docs?

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

As a result, the element has only class2instead of both.

Link Angular2 Visualization Documents

+4
source share
2 answers

It turns out that the option is isAddequivalent to the remove class, so to switch classes:

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

Oh, nothing strange is that you call a method setElementClassto delete it, of course ...

+9
source

Just note that Renderer is deprecated now and replaced with Renderer2 . There are two methods in the Renderer2 class that replace the setElementClass of the deprecated renderer.

  • To add a class:

    renderer.addClass('popup');

  • To remove a class:

    renderer.removeClass('popup');

+3
source

Source: https://habr.com/ru/post/1672565/


All Articles