2016-11-10 142 views
0

是否可以在ngStyle指令中爲屬性添加多個值?例如像:ngStyle對象表達式屬性角度2的多個值

<div [ngStyle]='{"background" : ["rgba(248,80,50,1)", "-webkit-gradient(left top, right top, color-stop(0%, rgba(248,80,50,1)), color-stop(50%, rgba(241,111,92,1)), color-stop(51%, rgba(246,41,12,1)), color-stop(71%, rgba(240,47,23,1)), color-stop(100%, rgba(231,56,39,1)))"]}' ></div> 

感謝

回答

1

在這個例子不能你只需要使用一個自定義類?在你的組件定義中,你可以用styleUrls爲特定的組件包含一個獨特的樣式表。例如:

@Component({ 
selector: 'my-component', 
moduleId: module.id, 
templateUrl: 'my-component.html', 
styleUrls: ['my-component.css'] // <-- here 
}) 

另一種方式可能更容易使用ngClass,如果你需要切換不同的風格爲好。

+0

感謝您的重播,我需要加載樣式dinamically,所以我認爲ngClass指令不能這樣做,與stylesUrl相同。 –

+0

我明白了。我沒有從你的例子中明白這一點。我確實找到了一個[示例](http://stackoverflow.com/questions/21364445/apply-css-style-attribute-dynamically-in-angular-js)如何使用Angular 1來做到這一點。也許你可以翻譯它讓Angular 2做你想做的事。希望有所幫助。 – Mickers