As per this link
I can do
<p [style.width.px]="30">
Some text that may be important.
</p>
This will set a width of 30 px. How do I do the same for percentage ?
<p [style.width.percent]="30"> // This doesn't work
Some text that may be important.
</p>
This is a super minor post; but, I just used the "%" (percent) symbol for in-line styles in Angular 4.2.3, and it totally worked. It's just another example of how the Angular template syntax is such a joy to work with.
Angular 9, Angular 10, Angular 11, Angular 12 The syntax of the style binding is similar to the property binding. The Style Binding uses the [] brackets. Place the CSS Style property (binding target) inside the square bracket. The CSS Style property must begin with ‘Style’ followed by a dot (.) and then style name.
Angular PercentPipe is an angular Pipe API that formats a number as a percentage according to locale rules. It belongs to CommonModule. Find the syntax. Find the description. number_expression: An angular expression that will give output a number. percent : A pipe keyword that is used with pipe operator and it converts number into percent.
Angular PercentPipe is an angular Pipe API that formats a number as a percentage according to locale rules. It belongs to CommonModule.
You use the %
symbol.
<p [style.width.%]="30">
You use what ever would normally come after the numeric value in CSS.
For example;
30rem => [style.width.rem]="30"
30px => [style.width.px]="30"
30% => [style.width.%]="30"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With