首页 > 解决方案 > 如何添加插值以获得 LI 的宽度?

问题描述

我想将 {{getCount(userObj.assigned_to, 'Applicable')}} + px 的相同值带到具有背景颜色的类的 LI 宽度,但是一旦我将相同的值添加到 style.width 就会出错。

Template parse errors: Parser Error: Got interpolation ({{}}) where expression was expected at column 1

<li class="chart__bar" [style.width]="{{getCount(userObj.assigned_to, 'Applicable')}}">{{getCount(userObj.assigned_to, 'Applicable')}}</li>

请建议如何获得 li 宽度。

标签: htmlcssangularinterpolation

解决方案


<li class="chart__bar" [ngStyle]="{'width': (getCount(userObj.assigned_to, 'Applicable')*10)+ '%'}">{{getCount(userObj.assigned_to, 'Applicable')}}</li>

推荐阅读