I am trying to set a background-image
for a div in a dynamic way from the backend.
I am using django (djangorestframework)
as the backend.
I am sending a http request and this is the data I received:
{
"user": "1ad54d3c-a012-431a-9e7a-8630fd9fb566",
"image": "api/media/users/1ad54d3c-a012-431a-9e7a-8630fd9fb566/tutorials/yyyy/_image/tutorialImage.png",
"title": "yyyy",
"description": "hgdhgdh",
"level": "professional",
"parts": 0,
"offical": false
}
This is the html:
<div class="tutorial-card">
<div class='tutorial-img' [style.background-image]="getTutorialImgURL(tutorial.image)">
</div>
The getTutorialImageURL
function:
public getTutorialImgURL(path: string){
return `url("http://${config.backendDomain}/${path}")`;
} // config.backendDomain is "localhost:8000"
It doesn't appear to send a get request to the backend (the url path is right)
things I have tried:
changing the prefix from
http
to 'https'- it works but the backend doesnt yet support
https
so it returnscode 400
- it works but the backend doesnt yet support
using
[ngStyle]="{'background-image': getTutorialImgURL(tutorial.image)}"
- still correct path but doesnt send the request
- make
getTutorialImgURL
return the full style (return
image-backgr: url("http://${config.backendDomain}/${path}")`)- same as all corrent path not sending http requst
- using
DomSanitizer
(return this.sanitizer.bypassSecurityTrustStyle(
url("http://${config.backendDomain}/${path}"));)
- still, as before: correct path not sending http request to the backend
(I don't want to use <img [src]='...'>
)