【问题标题】:Multiple attributes in ng-styleng-style 中的多个属性
【发布时间】:2015-06-08 18:16:51
【问题描述】:

我需要多个原始样式属性,例如:

$scope.css = "'width': 'calc(100% - "+$scope.fixedColumnsWidth+"'),'margin-left':'"+ $scope.fixedColumnsWidth+"'";

<div ng-style="{css}">

这不起作用。当我使用它时它可以工作

<div style="{{css}}">

但不适用于 IE。

【问题讨论】:

    标签: css angularjs ng-style


    【解决方案1】:

    ng-style 等待一个对象字面量,所以你需要将你的代码调整为

    $scope.css = {
     width: 'calc(100% -'+$scope.fixedColumnsWidth+')',
     'margin-left': $scope.fixedColumnsWidth
    }
    
    <div ng-style="css"></div>
    

    【讨论】:

      【解决方案2】:

      在视图下方使用

      <div ng-style="{
         'width': calc('100% -'+fixedColumnsWidth),
         'margin-left': fixedColumnsWidth}">
      

      【讨论】:

        猜你喜欢
        • 2012-05-31
        • 2017-07-03
        • 2017-11-22
        • 2014-06-13
        • 2017-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-29
        相关资源
        最近更新 更多