3

The image path is defined in item.imagePath.

<div *ngFor="let item of itemList">
   <div style="background-image: url(item.imagePath)" class="thumb">
       <span>{{item.productName}}</span>
   </div>
   <div>
       <p>{{item.productFeature}}</p>
   </div>
</div>

style="background-image: url(item.imagePath)"
What is the correct syntax as this does not work?

1

2 Answers 2

3

The styles are updated according to the value of the expression evaluation:

keys are style names with an optional . suffix (ie 'top.px', 'font-style.em'), values are the values assigned to those properties (expressed in the given unit).

<div [ngStyle]="{'background-image': 'url(' + photo + ')'}"></div>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

 <div *ngFor="let item of itemList">
       <div class="thumb">
           <img src="{{item.imagePath}}" />
           <span>{{item.productName}}</span>
       </div>
       <div>
           <p>{{item.productFeature}}</p>
       </div>
    </div>

1 Comment

it seems like img src is workable if the path is absolute, item.imagePath that I have is relative, thus would require to generate the url (background-image:url). Do you have alternative?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.