无法使用样式绑定更改Angular中的背景颜色 [英] unable to change the background color in Angular using style binding
本文介绍了无法使用样式绑定更改Angular中的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Angular进行样式绑定时, div
的背景颜色不变.该代码位于下面以供参考
The background color of the div
is not changing when using the style binding using Angular.The code is placed below for reference
@Component({
selector: 'course',
template: `
<div [style.backgroundColor]='red'>
<button (click)="onClick($event)" class="btn btn-primary" [class.active]="isActive" [style.backgroundColor]='red'>Save</button>
</div>
`,
styleUrls: ['./course.component.css']
})
export class CourseComponent {...}
样式元素具有 backgroundColor
属性.我要去哪里错了?
The style element has the backgroundColor
property. Where am I going wrong?
推荐答案
角度属性绑定需要一个表达式,而不是您要分配的值.可能要使用 [style.backgroundColor] ='red'"
来代替 [style.backgroundColor] ='red'
,请注意,我在上面加上了'red'引号.
Angular property binding expects an expression instead of a value which you are trying to assign.
Instead of [style.backgroundColor]='red'
you might want to use [style.backgroundColor]="'red'"
note that i have wrapped 'red' on quotes.
这篇关于无法使用样式绑定更改Angular中的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文