如何在Angular 2中将Object传递给NgStyle指令?
发布时间:2020-12-17 07:23:19 所属栏目:安全 来源:网络整理
导读:我正在尝试将NgStyle指令与对象变量一起使用,如下所示: @Component({ template: ` div [ngStyle]="object" some test text /div` })export class example { private object: string = "{background-color: 'white'}";} 我也尝试使用object =“background-co
我正在尝试将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}”,但似乎它不起作用.我收到消息错误:
我究竟做错了什么?
不要将字符串传递给
[ngStyle] ,传递一个对象,它将起作用:
private object: Object = { 'background-color': 'red'}; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |