Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 383
TrtG Avatar asked Apr 03 '15 16:04

TrtG


People also ask

Can you have multiple NgStyle?

With style binding we can set only a single style, however to set multiple styles we can use ngStyle directive.

How do I add multiple styles in NgStyle?

Use property binding to style one CSS property of an element and use the ngStyle directive to set multiple CSS properties. Both tools make it super easy to dynamically style elements.

Can we use NgStyle and NgClass together?

Combining NgStyle and NgClass Directives with our knowledge of Angular Template Syntax, we can marry conditional styling with Angular's Property & Event Binding.

What is difference between NgStyle and NgClass?

The NgClass and NgStyle directives are used to apply style to the HTML element conditionally. The NgClass allows you to apply whole class based on condition whereas NgStyle gives you more flexibility to set individual properties.


2 Answers

Use below on view

<div ng-style="{
   'width': calc('100% -'+fixedColumnsWidth),
   'margin-left': fixedColumnsWidth}">
like image 188
Pankaj Parkar Avatar answered Oct 18 '22 02:10

Pankaj Parkar


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>
like image 31
Ins Avatar answered Oct 18 '22 02:10

Ins