在 Internet Explorer 的 angularjs 中未访问范围变量

scope variable is not accessed in angularjs in internet explorer

我有一个自定义指令,我在其中计算宽度并将其分配给范围变量。该作用域变量在 html 中被访问,在 firefox 和 chrome 中工作正常。但在 Internet Explorer 中没有。

控制器中的代码

cellWidth: 160 // property of an object

指令中的代码

for (var i = 0; i < totalColumns; i++) {
    scope.columnMapping.columns[i].tempCellWidth = scope.columnMapping.columns[i].cellWidth * 100) / tableWidth;
}

HTML

<div style="width: {{column.tempCellWidth}}%;"> {{columnName}} </div> // IE does not evaluate this.. 

IE 在检查元素时显示宽度:{{column.tempCellWidth}}%。

提前致谢。

您需要使用 ng-style 属性而不是直接使用 style

<div ng-style="{ width: column.tempCellWidth }"> {{columnName}} </div>

还要附加百分号 (%),您应该在 for 循环中添加

for (var i = 0; i < totalColumns; i++) {
    scope.columnMapping.columns[i].tempCellWidth = (scope.columnMapping.columns[i].cellWidth * 100) / tableWidth) + '%';
}