Search code examples
cssangularjsng-style

Multiple attributes in ng-style


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.


Solution

  • 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>