2014-11-21 166 views
6

不更新我創建在角的簡單指令,它產生一滾輪,以顯示一些產品。問題IE

我在與代碼的一部分的問題。

  <ul ng-style="{'margin-left':{{currentMargin}}+'px'}"> 
       <li ng-repeat="tyre in tyres" ng-style="{'width':{{liWidth}}+'px'}"> 
        <div class="imageContainer"><img src="../Images/eutl/{{tyre.image}}"/></div> 
        <div class="details"> 
         <h3>{{tyre.name}}</h3> 
         <a href="{{tyre.link}}">About this tire</a> 
        </div> 
       </li> 
      </ul> 

and this is what it looks like in the browser once executed 
<ul ng-style="{'margin-left':0+'px'}"> 
<!-- ngRepeat: tyre in tyres --> 
<li ng-repeat="tyre in tyres" ng-style="{'width':265+'px'}" class="ng-scope" style="width: 265px;"> 
    <div class="imageContainer"><img src="../Images/eutl/tire.jpg"></div> 
    <div class="details"> 
     <h3 class="ng-binding">Fuel Efficient</h3> 
     <a href="#">About this tire</a> 
    </div> 
</li> 
<!-- end ngRepeat: tyre in tyres --></ul> 

我的網頁上執行此之後,我得到的滾動條和「禮」元素中的NG-Style獲取正確顯示,而NG式的「UL」沒有。

我試過多種解決方案,甚至還試圖從「禮」元素添加完全相同的NG-風格,它只是沒有得到處理,不添加風格。

誰能幫我指出了我的標記錯誤或可能的原因一個NG式工作的李元素和其他沒有工作的UL本身?

時遇到的另一個問題是,currentMargin的值未在IE8/9更新等。

感謝

回答

7

ng-style接受一個Angular expression中的一個對象。這意味着,如果要使用該表達式中的變量,則可以直接使用它(沒有雙花括號):

ng-style="{width: liWidth + 'px'}" 

雙花括號中使用時要插入一個動態的,內插的值,以一個接受字符串的參數,如<img alt="{{product.name}} logo">。然後你在裏面放置一個表達式

+0

驚人的,它的工作原理。感謝您的解釋! – 2014-11-21 11:21:49

+0

保存我的一天,歡呼! – Sohail 2016-12-12 12:38:12

5

儘量做到:

ng-style="{'width':liWidth+'px'}"> 

沒有花括號,很多NG指令不喜歡它