0

I have some code like that:

<div [ngStyle]="{'background': 'url(' + order.image_url_medium + ') top right no-repeat #118cc8'}">Content</div>

But how can I bind it depending on condition? So if order.image_url_medium exists, put it to style <div [ngStyle]="{'background': 'url(' + order.image_url_medium + ') top right no-repeat #118cc8'}">Content</div>, else - just - leave blank div <div>Content</div>

1 Answer 1

2

In your view:

<div [ngStyle]="divStyle">Content</div>

In your component:

this.divStyle = {};
if (someCondition) {
    this.divStyle.background = `url(${this.order.image_url_medium}) top right no-repeat #118cc8`;
}
Sign up to request clarification or add additional context in comments.

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.