我正在尝试将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 zone.js@0.6.21?main=browser:346_loop_1 @ VM1051 zone.js@0.6.21?main=browser:371drainMicroTaskQueue @ VM1051 zone.js@0.6.21?main=browser:375ZoneTask.invoke @ VM1051 zone.js@0.6.21?main=browser:297
我究竟做错了什么?
不要将字符串传递给
原文链接:https://www.f2er.com/angularjs/141824.html[ngStyle]
,传递一个对象,它将起作用:
private object: Object = { 'background-color': 'red'};