37

Using an expression like this on the style attribute works on Chrome but doesn't work on IE8

style="width:{{progress}}%"

http://jsfiddle.net/5VDMD/12/ (to test it please type a number in the textbox)

Any workaround for this problem?

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Christian Quirós
  • 494
  • 1
  • 5
  • 9

5 Answers5

57

Try

ng-style="{ width: progress + '%' }"
Aleksandr Sabov
  • 665
  • 7
  • 8
26

I had to use ng-attr-style (though I didn't need to use a function).

<div ng-attr-style="width: {{value}}%"></div>

Here is a github discussion about this issue.

Jason
  • 8,400
  • 10
  • 56
  • 69
13

I made it work that way:

in the controller:

$scope.getStyle = function(progress){
    return {
        width: progress + "%"
    }
}

in the HTML:

<div class="progbar" ng-style="getStyle(progress)"></div>
user2106730
  • 131
  • 1
  • 4
4

For some reason in IE I had to use

ng-attr-style="{{METHOD_TO_RETURN_SOME_STYLE()}}"

Though mine was in a directive under an ng-repeat.

Brandon.Staley
  • 1,742
  • 21
  • 25
0

if anybody use px instead of %, you have to use this

ng-style="{ width: progress + \'px\' }"
Alamgir
  • 686
  • 8
  • 14
  • I think it would be more helpful for theOP and further users,when you add some explaination for your intension – Reporter Aug 07 '14 at 11:52