我正在嘗試允許用戶在運(yùn)行時更改styleUrls值,因此我嘗試以下操作:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
// styleUrls: [ './app.component.css' ]
styleUrls: [styleUrl]
})
export class AppComponent implements OnInit {
styleUrl = './app.component.css'
ngOnInit() {
this.styleUrl = './another.css';
}
}
這不起作用,所以有可能讓這樣的東西起作用嗎?
如果是,怎么做?
這樣不行。下面是一個簡單的示例,其中包含兩個css文件和ngClass
下面是根據(jù)用戶交互使組件變亮/變暗。
樣式表-light(app.component.light.css)
樣式表-dark(app.component.dark.css)
現(xiàn)在為整個組件創(chuàng)建一個基本包裝器div
如果改用SCS,您可以像在html中一樣使用包裝器