任务是根据路径更改背景颜色。我必须为UpcomingComponent显示不同的颜色,而对于其他路线,背景颜色将保持不变。以组件Angular 2的样式设置值
我试图在STYLES中为for/deep/.classname动态设置背景颜色的值。
下面是代码
@Component({
selector: 'app-upcoming',
templateUrl: './upcoming.component.html',
// styleUrls: ['./upcoming.component.css'],
styles: [`
/deep/ .root {
background-color: color;
}`]
})
export class UpcomingComponent implements OnInit {
color: string;
ngOnInit() {
this.bodyBackgroundImage();
}
bodyBackgroundImage() {
if (window.location.pathname === '/upcoming'){
console.log("Here i am");
this.color = 'purple';
}
}
}
我认为这尚未支持。 – micronyks
原因是所有样式都是在你的类被实例化之前编译的。 – Milad