我試圖使用NgStyle
指令與對象變量,像這樣:如何將Object傳遞給Angular 2中的NgStyle指令?
@Component({
template: `
<div [ngStyle]="object">
some test text
</div>`
})
export class example {
private object: string = "{background-color: 'white'}";
}
我也試圖與object = "background-color: 'red'"
和[ngStyle]="{object}"
,但似乎這是行不通的。我收到消息錯誤:
Error: Uncaught (in promise): Error caused by: Cannot find a differ supporting object '{color: 'white'}'(…)consoleError @ VM1051 [email protected]?main=browser:346_loop_1 @ VM1051 [email protected]?main=browser:371drainMicroTaskQueue @ VM1051 [email protected]?main=browser:375ZoneTask.invoke @ VM1051 [email protected]?main=browser:297
我在做什麼錯?
「作爲一個對象,像這樣」但你傳遞一個字符串。 – msanford