首页 > 解决方案 > 减去 [ngStyle] 角度 6 内的变量

问题描述

我正在width通过减去变量regOtValueendTimeOverTimeOut在我的 [ngStyle] 指令中使我的进度条的样式属性动态化。但它总是抛出空白或插值错误(通过{{ }}在 [ngStyle] 内添加)

这就是我正在做的事情:

 [ngStyle]="{'width': (getAttendance.regOtValue - getAttendance.attendance[getAttendance.findIndex].endTimeOverTimeOut) + '%', 'background-color': '#63B3EA'}"

请帮助我跟踪我的发展。

先感谢您!

标签: javascriptangulartypescriptdom

解决方案


尝试从如下方法返回一个值:

内部.ts文件:

getWidth() {
 return (this.getAttendance.regOtValue - this.getAttendance.attendance[getAttendance.findIndex].endTimeOverTimeOut).toString() + '%';
}

在您的模板中:

 [ngStyle]="{'width':getWidth(), 'background-color': '#63B3EA'}"

推荐阅读