繁体   English   中英

angular 8 中 ng-attr-style 的等价物是什么?

[英]what is the equivalent of ng-attr-style in angular 8?

我在 angularjs 中有一个应用程序,我想将其转换为 Angular 8。在应用程序中,有一个 div,我正在像这样动态地传递宽度

ng-attr-style="width:{{countersDtl.SurveySubmittedInstant/(countersDtl.ServiceDone)*100}}%"

countersDtl 是一个具有键 SurveySubmittedInstant 和 ServiceDone 的对象。

我有多个元素仅像这样使用 ng-attr-style。

我已经尝试了从 [style.width] 到 [ngStyle] 的所有内容,但没有任何效果。

ng-attr-style的等价物是ngStyle绑定。 您可以在文档中阅读有关ngStyle更多信息。

您的案例的正确语法可能如下所示:

[ngStyle]="{'width': (countersDtl.SurveySubmittedInstant/(countersDtl.ServiceDone)*100) + '%'"

此外,您可以使用而不是+ '%'将属性标记为'width.%' ,如下所示:

[ngStyle]="{'width.%': countersDtl.SurveySubmittedInstant/(countersDtl.ServiceDone)*100"

还有第三种可能绑定到width本身,如下所示:

[style.width.%]="countersDtl.SurveySubmittedInstant/(countersDtl.ServiceDone)*100"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM