작업은 경로에 따라 배경색을 변경하는 것입니다. UpcomingComponent에 대해 다른 색상을 표시해야하고 다른 색상에 대해서는 배경색이 동일하게 유지되어야합니다.구성 요소의 스타일 값 설정 각도 2
배경색을 동적으로 설정하기 위해 STYLES for/deep/.classname에 값을 설정하려고합니다.
다음은 지원되지 않습니다 styles
또는 styleUrls
에 바인딩 코드
@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
이유는 클래스 get이 인스턴스화되기 전에 모든 스타일이 컴파일되기 때문입니다. – Milad