Skip to content Skip to sidebar Skip to footer

Ngstyle Background-image

I have the following problem. I have a component that has @Input string value that is a link to the image. In my HTML file I have:

Solution 1:

Try this

<divclass="parallax" [ngStyle]="{'background-image': 'url('+ parallaxImage+')'}"></div>

or

getParallaxImage(){
    return"url(" + this.parallaxImage + ")";
  }

Both solutions will work now, use as per your requirements.

Solution 2:

This should also work:

[style.background-image]="'url(' + parallaxImage + ')'"

Post a Comment for "Ngstyle Background-image"