Set background-image by variable

hi guys,
I have one question,
can i set div background-image using variable/data-binding
i have tried these code bellow but not working,
please help
<div class="background" style="background-image:url('{{myProfile?.ProfilePic}}')"></div>

in css:

.background{
        height: 100%; 
        background-attachment: fixed;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
    }
1 Like

I think with the ngStyle, the bg works.

<div class="background" [ngStyle]="{'background-image': 'url(' + myProfile?.ProfilePic + ')'}"></div>

2 Likes

thank u so much… it solved my problem
thanks again

1 Like