【问题标题】: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}">