Reputation: 448
I'm trying to set background image using setElementStyle as below but not working.
this.renderer.setElementStyle(document.body, 'backgroundImage', this.backgroundImageUrl);
I also tried,
this.renderer.setElementStyle(document.body, 'background-image', this.backgroundImageUrl);
Please let me know if it's possible to set background image using setElementStyle?
Thank you.
Upvotes: 2
Views: 634
Reputation: 1212
Put this.backgroundImageUrl
inside url() then above code will work fine.
this.renderer.setStyle(document.body, 'backgroundImage', 'url('+this.backgroundImageUrl+')');
Upvotes: 0
Reputation:
setElementStyle
is from Renderer. And it is depreciated. Renderer2 uses setStyle
:
setStyle(el: any, style: string, value: any, flags?: RendererStyleFlags2): void
And import it:
import { Renderer2 } from '@angular/core';
Upvotes: 1