Reputation: 378
I've looked around similar answers found within stackoverflow but no luck. How can I correctly use interpolation inside the ngStyle for background-image?
This is the code I've use:
<div mat-card-avatar class="header-image" ngStyle = "{'background-image': 'url(' + {{cardData.image}} + ')'}"></div>
I am getting Error: Cannot find a differ supporting object '{'background-image': 'url(' + ../../assets/image/photo.png + ')'}' at .....
Upvotes: 1
Views: 1204
Reputation: 124
[ngStyle]="'{background-image: url(' + {{cardData.image}} + ')}'"
unsure if its even possible, however this would be correct for the quote marks
Upvotes: 0
Reputation: 22203
You cannot use interpolation inside ngStyle
, you have to use [ngStyle]="{'background-image': 'url(' + cardData.image + ')'}"
Try like this:
<div mat-card-avatar class="header-image" [ngStyle]="{'background-image': 'url(' + cardData.image + ')'}">
Upvotes: 3
Reputation: 736
Try to wrap your ngStyle attributes in square brackets:
[ngStyle]="...
Upvotes: 0