【问题标题】:AngularJS expression not working within style attribute on IE8AngularJS 表达式在 IE8 上的样式属性中不起作用
【发布时间】:2012-11-22 21:51:12
【问题描述】:

在样式属性上使用这样的表达式在 Chrome 上有效,但在 IE8 上无效

style="width:{{progress}}%"

http://jsfiddle.net/5VDMD/12/(要测试它,请在文本框中输入一个数字)

有解决这个问题的办法吗?

【问题讨论】:

标签: templates internet-explorer-8 expression angularjs


【解决方案1】:

试试

ng-style="{ width: progress + '%' }"

【讨论】:

  • 谢谢!这是最好的答案。
  • 我需要在 Angular 1.5 的 css 属性周围加上单引号,如下所示:ng-style="{ 'width' : progress + '%' }"
【解决方案2】:

我必须使用ng-attr-style(虽然我不需要使用函数)。

<div ng-attr-style="width: {{value}}%"></div>

这里是关于这个问题的github discussion

【讨论】:

    【解决方案3】:

    我是这样做的:

    在控制器中:

    $scope.getStyle = function(progress){
        return {
            width: progress + "%"
        }
    }
    

    在 HTML 中:

    <div class="progbar" ng-style="getStyle(progress)"></div>
    

    【讨论】:

      【解决方案4】:

      出于某种原因,我不得不在 IE 中使用

      ng-attr-style="{{METHOD_TO_RETURN_SOME_STYLE()}}"
      

      虽然我的在 ng-repeat 下的指令中。

      【讨论】:

        【解决方案5】:

        如果有人使用 px 而不是 %,你必须使用这个

        ng-style="{ width: progress + \'px\' }"
        

        【讨论】:

        • 我认为当您为您的意图添加一些解释时,它会对OP和其他用户更有帮助
        猜你喜欢
        • 2014-06-29
        • 1970-01-01
        • 1970-01-01
        • 2018-02-06
        • 2023-02-06
        • 2015-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多