2012-12-05 37 views
35

樣式屬性內工作的樣式屬性適用於Chrome,但在IE8AngularJS表達不是IE8

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

http://jsfiddle.net/5VDMD/12/(不工作,以測試它,請在文本框中鍵入一個數字使用像這樣的表達)

針對此問題的任何解決方法?

+2

您可能想嘗試使用'ng-style'。 – Tosh

+2

解決方案是ng-style =「{width:propertyInScope +'%'}」感謝David https://groups.google.com/forum/?fromgroups=#!topic/angular/Bb6087Gv284 – user1877925

+0

這裏是jsfiddle在IE8上工作正常的解決方案http://jsfiddle.net/5VDMD/15/ – user1877925

回答

55

嘗試

ng-style="{ width: progress + '%' }" 
+0

謝謝!這是最好的答案。 – Tom

+3

我需要圍繞Angular 1.5的css屬性使用單引號,如下所示: 'ng-style =「{'width':progress +'%'}」' – NathanQ

13

我做了工作方式:

控制器:

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

在HTML:

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

出於某種原因,在IE瀏覽器我不得不使用

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

雖然我是在ng-repeat下的指令。

0

如果有人使用PX代替%,你就必須使用這個

ng-style="{ width: progress + \'px\' }" 
+0

我認爲這對於更多用戶來說會更有幫助,當你爲你的內涵添加一些解釋 – reporter

25

我不得不使用ng-attr-style(雖然我沒有需要使用的功能)。

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

這是關於此問題的github discussion