Multiple attributes in ng-style

2020-04-01 08:44发布

I need to have multiple raw style attributes like :

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

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

This is not working. It works when I use

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

But not for IE.

2条回答
贼婆χ
2楼-- · 2020-04-01 08:57

Use below on view

<div ng-style="{
   'width': calc('100% -'+fixedColumnsWidth),
   'margin-left': fixedColumnsWidth}">
查看更多
Anthone
3楼-- · 2020-04-01 09:07

ng-style waits for an object literal, so you need to adjust your code to

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

<div ng-style="css"></div>
查看更多
登录 后发表回答