Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scope variable is not accessed in angularjs in internet explorer

I have a custom directive in which i am calculating width and assigning it into scope variable. That scope variable is being accessed in html which is working fine in firefox and chrome. But not in Internet explorer.

code in controller

cellWidth: 160 // property of an object

Code in directive

for (var i = 0; i < totalColumns; i++) {
    scope.columnMapping.columns[i].tempCellWidth = scope.columnMapping.columns[i].cellWidth * 100) / tableWidth;
}

HTML

<div style="width: {{column.tempCellWidth}}%;"> {{columnName}} </div> // IE does not evaluate this.. 

IE shows width: {{column.tempCellWidth}}% while inspecting an element.

Thanks in advance.

like image 216
Alpesh Prajapati Avatar asked Jan 28 '26 17:01

Alpesh Prajapati


1 Answers

You need to use the ng-style attribute instead of style directly.

<div ng-style="{ width: column.tempCellWidth }"> {{columnName}} </div>

Also to append the percentage sign (%), you should do it in your for loop

for (var i = 0; i < totalColumns; i++) {
    scope.columnMapping.columns[i].tempCellWidth = (scope.columnMapping.columns[i].cellWidth * 100) / tableWidth) + '%';
}
like image 115
Mike Vranckx Avatar answered Jan 30 '26 12:01

Mike Vranckx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!