I have a div
in which I show a Base64 image using CSS:
.my-image {
background: url('data:image/jpg;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==');
}
Now this image could be different because I retrieve it from back-end so I have to change it dinamically.
So I have removed CSS and I have tried some solution in the component such as the following:
<div [style.background]="'url(' + myImage + ')'"></div>
<div [ngStyle]="{'background-image':'url('+ myImage +')'}"></div>
and some others... but none worked.
I have also sanitized the image in the component, using some methods of DomSanitizer
like this:
this.sanitizer.bypassSecurityTrustResourceUrl(this.myImage)
But even this doesn't do the trick :(
Do you know a working way to have div
with dynamic background image?
Here is my CSS now:
div {
width: 3em;
height: 3em;
}