Reputation: 457
Is it possible to use my variable inside calc() inside [style.width] directive in angular?
Something like this:
<div [style.width.px]="calc(100% - myWidth)">some texts </div>
Upvotes: 0
Views: 566
Reputation: 96
You can also declare a style object in your .ts file:
mywidth = 20;
styleObj = {width: `calc( 100% - ${this.mywidth}px)`};
and put it into your html:
<div [ngStyle]="styleObj">some texts </div>
Upvotes: 2
Reputation: 22213
Yes.
TS:
myWidth: string = '100px';
HTML:
<div [style.width]="'calc(100% - ' + myWidth + ')'">some texts </div>
Upvotes: 3