AngularJS expression not working within style attribute on IE8
Asked Answered
C

5

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?

Calotte answered 5/12, 2012 at 5:40 Comment(4)
You may want to try using 'ng-style' instead.Choriocarcinoma
The solution was ng-style="{width: propertyInScope + '%'}" thanks to David groups.google.com/forum/?fromgroups=#!topic/angular/Bb6087Gv284Disinterest
Here is the jsfiddle with the solution working ok on IE8 jsfiddle.net/5VDMD/15Disinterest
This doesn't work even in IE11 btw.Nesto
W
57

Try

ng-style="{ width: progress + '%' }"
Wilfordwilfred answered 18/6, 2013 at 13:34 Comment(1)
I needed single quotes around the css property for Angular 1.5, like so: ng-style="{ 'width' : progress + '%' }"Sewerage
D
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.

Diantha answered 19/9, 2014 at 17:49 Comment(0)
N
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>
Nephelometer answered 25/2, 2013 at 9:43 Comment(0)
R
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.

Rudolfrudolfo answered 10/12, 2013 at 13:35 Comment(0)
P
0

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

ng-style="{ width: progress + \'px\' }"
Psychasthenia answered 7/8, 2014 at 11:9 Comment(1)
I think it would be more helpful for theOP and further users,when you add some explaination for your intensionMiscount

© 2022 - 2024 — McMap. All rights reserved.