2

I need to set this properties on my div:

background: url();
background-repeat: no-repeat;
background-size: cover;
background-position: center, center;

This is my div:

<div *ngFor="let orderItems of receiptItems;" class="order-article animated bounceInLeft">
  <div class="order-img"   [style.background]="'url('+ orderItems.product.img.url +')'" ></div>
  <div class="order-title">
    <p>{{orderItems.product.title}}</p>
  </div>
</div>

As you can see guys I've set [style.background] url but I don't know how to set rest of the attributes / multiple attributes..

Thanks Any kind of help would be great !

-------- EDIT:

 <div *ngFor="let orderItems of receiptItems;" class="order-article animated bounceInLeft">
      <div class="order-img"   [ngStyle]="{'background':'url('+ orderItem.product.imgUrl +')', 'background-repeat':' no-repeat','background-size': 'cover;','background-position': 'center, center' }" ></div>
      <div class="order-title">
        <p>{{orderItems.product.title}}</p>
      </div>
    </div>

using ngStyle caused this:

enter image description here

attributes are not applied properly...

1

2 Answers 2

2

use the ngStyle tag

<div   [ngStyle]="{'background-image':'url( orderItem.product.imgUrl )', 'background-repeat':' no-repeat','background-size': 'cover','background-position': 'center, center' }"  class="order-img"  ></div>

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Why did you change background to background-image?
0

Try this.

CSS

.order-img{
background: url(--content);
background-repeat: no-repeat;
background-size: cover;
background-position: center, center;
}

HTML

<div *ngFor="let orderItems of receiptItems;" class="order-article animated bounceInLeft">
  <div class="order-img" [attr.outage-count]="orderItems.product.img.url" ></div>
  <div class="order-title">
    <p>{{orderItems.product.title}}</p>
  </div>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.