【问题标题】:scope variable is not accessed in angularjs in internet explorer在 Internet Explorer 的 angularjs 中未访问范围变量
【发布时间】:2015-11-11 02:53:58
【问题描述】:

我有一个自定义指令,我在其中计算宽度并将其分配给范围变量。该范围变量正在 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}}%。

提前致谢。

【问题讨论】:

    标签: html angularjs internet-explorer angularjs-scope directive


    【解决方案1】:

    您需要直接使用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) + '%';
    }
    

    【讨论】:

    • 您能否提供更多详细信息究竟是什么不工作?您是否在 IE 上设置了带有值的 style width 属性?
    • 嘿,它起作用了...我做了完全相同的事情...(%) 在循环中...谢谢人..高兴
    猜你喜欢
    • 2015-06-20
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    • 2017-12-13
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多