1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Can Angular Renderer2 setStyle function operate on an element where the style attribute is not...

Discussão em 'Angular' iniciado por 0x1211, Setembro 27, 2024.

  1. 0x1211

    0x1211 Guest

    In an Angular application let's suppose we have a body element as

    <body>
    ...
    </body>


    and now I want to set its background to some value using Angular Renderer2 as

    this.renderer.setStyle(document.body, 'background', 'url("some-example-url");');


    and nothing happens.

    But now if I do it using setAttribute function as

    this.renderer.setAttribute(document.body, 'style', 'background: url("some-example-url");');


    this will work out fine.

    My question is: can setStyle function operate on an element where the style attribute is not yet defined ?

    Continue reading...

Compartilhe esta Página