I am encountering an issue in my Angular application where I am unable to load background images dynamically from my backend.
Displaying regular pictures is not a problem for me.
However, the background images are not loading and I do not receive any error messages to troubleshoot the issue.
The version of Angular I am using is 7.3.8.
I have attempted various solutions found on Stack Overflow and other resources online, but unfortunately, nothing seems to be working.
This is how the layout looks in my HTML:
<div *ngIf="headerImage" [style.background-image]="headerImage">
Within my Layout Component:
ngOnInit() {
this.setup = this.route.snapshot.data['setup'];
this.createHeader(this.setup)
}
createHeader(setup: Setup){
const tempImage = 'data:image/png;base64,' + this.setup.headerImage.data;
this.headerImage = this.sanitizer.sanitize(SecurityContext.STYLE, 'url(' + tempImage + ')');
console.log(this.headerImage);
}
When I check my console, I see this output:
this.headerImage console.log: url(data:image/png;base64,iVBORw0KGgo.......
I have also tried utilizing the following code:
[ngStyle]="{'background-image':' url(' + headerImage + ')'}"
this.backgroundImg = sanitizer.bypassSecurityTrustStyle('url(....)'
Despite trying these options, I am still unable to resolve the issue with loading background images. Regular image display works fine, but the background image is necessary for my application.
If anyone could offer insight or assistance, it would be greatly appreciated!