我正在尝试根据额定值更改此跨度的宽度。在这种情况下,“质量”为1到5。如果等级为5,则宽度应为100%。如何将其与ng-style绑定?
<span class="rating-box" ng-style="{ 'width': {{star.quality*20}} + '%' }"></span>
此代码无效。我收到此错误:
Template parse errors:
Can't bind to 'ng-style' since it isn't a known property of 'span'. (" <small>Calitate</small>
非常感谢!
正确的语法是:<span class="rating-box" [ngStyle]="{ 'width': {{star.quality*20}} + '%' }"></span>
您可以在官方文档中找到此指令的选择器定义:https://angular.io/api/common/NgStyle
这是您需要使用的角度8的语法错误
<span class="rating-box" [ngStyle]="{ 'width': star.quality*20 + '%' }"></span>