2016-01-12 81 views
0

style屬性被添加到基於添加到元素的ng樣式表達式的元素中.Below是動態添加背景色到Style屬性的代碼。Angular JS ng-style

  <div class="legend"> 
      <span data-ng-repeat="item in history[0].costItems"><i ng-style="{ 'backgroundColor':item.graphColor}"></i><p> {{item.itemLabel}}</p></span> 
      </div> 

item.graphcolor是NG-重複的一部分,上述(任何標籤)DIV將環在屏幕以顯示許多div的,但每個格將具有不同的backgroung色。

它在屏幕上使用顏色工作正常,但以PDF格式打印時,它不可見。是否有可能的方式將'!important'附加到style屬性中的背景顏色,以便它以PDF格式顯示。

我嘗試使用jQuery連接!對於style屬性很重要,但它被附加在控制檯中並顯示在警告框中,但未反映在元素的style屬性中。

我甚至試過替換';' '!important',它的功能也是如此。

任何其他方法來解決這個問題?

回答

0

我最好的,因爲你沒有給太多的代碼的建議是看

@media print { 
    .print_class { 
     background: red; 
    } 
} 

您可能需要使用的角度指令

脫身
<div class="legend"> 
    <span data-ng-repeat="item in history[0].costItems"> 
    <i style="background-color: {{item.graphColor}}"></i> 
    <p> {{item.itemLabel}}</p></span>  
</div> 
+0

我試圖讓從項目顏色.graphColor ---->這會告訴我要顯示爲背景的顏色....但添加類屬性將顯示我想要的顏色。 – user2918673

+0

ng-class也會動態添加css,但是它仍然可以追加'!important'..在我的問題中添加了代碼Steven – user2918673

+0

如何使用

{{item.itemLabel}}