2

How do I use the Angular style binding syntax with the css calc() function for dynamically setting the width of an element.

With React I could simply write :-

<div style = {{
   width: `calc((${currentStep - 1 } * (100% / ${steps - 1})) - 6px)`
}}>

</div>

With Angular I want to accomplish the same thing :-

<div
[style.width] = `calc((${currentStep - 1 } * (100% / ${steps - 1})) - 6px)`
>
  
</div>
1
  • Thanks @AbuSufian, That dosen't work either. Commented Feb 12, 2021 at 11:04

1 Answer 1

0

You can try something like:

[style. width]="getWidth(currentStep, steps)"

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

3 Comments

Thanks Yugi, That doesn't work either, how ever this approach works with ngStyle. But the problem is I want to use the [style.width[] approach without having a method in my class file
That is impossible in angular, you can't use [..]={{..}} See: stackoverflow.com/questions/40203279/…
You can do style.width="stuff with {{}}", though; it's just the [bracket] syntax you can't use. But since you can't use the calc built-in, it doesn't really help matters.

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.