ng风格的多个属性

Trt*_*rtG 28 css angularjs ng-style

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

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

<div ng-style="{css}">
Run Code Online (Sandbox Code Playgroud)

这不起作用.它在我使用时有效

<div style="{{css}}">
Run Code Online (Sandbox Code Playgroud)

但不适用于IE.

Pan*_*kar 35

在视图中使用以下

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


Ins*_*Ins 23

ng-style等待对象文字,因此您需要将代码调整为

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

<div ng-style="css"></div>
Run Code Online (Sandbox Code Playgroud)