1

I want to set the width as dynamically with the data that i am gonna take from the array. But angular doesn't let me set it with usual way. How can i handle it ?

<div *ngFor="let item of products">
    <div [style.width.px]="{{ item.size }}" class="Holiday"></div>
</div>

2 Answers 2

2

you do not need {{ }} when you're using [].

change [style.width.px]="{{ item.size }}" to [style.width.px]="item.size" and it should work.

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

Comments

2

Use ngStyle to apply dynamic styles.

<div *ngFor="let item of products">
    <div [ngStyle]="{ 'width' : item.size+'px' }" class="Holiday"></div>
</div>

Demo : https://stackblitz.com/edit/angular-fel5sk

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.