[英]Use variables inside @component styles
I want to generate some dynamic CSS and use it inside the styles of @component.我想生成一些动态 CSS 并在 @component 的样式中使用它。 I don't know exactly how to pass that variable and wonder even if it is possible to do this.
我不确切知道如何传递该变量,并且想知道是否可以这样做。 Here is the piece of code that uses the variable "stylesArray".
这是使用变量“stylesArray”的一段代码。
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
styles: stylesArray,
encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
stylesArray: string[] = [
// Generate some dynamic css here
];
}
You can do it with the host decorator property:您可以使用主机装饰器属性来做到这一点:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
encapsulation: ViewEncapsulation.None,
host: {
'[style]': 'stylesArray'
}
})
export class AppComponent {
stylesArray: string[] = [
// Generate some dynamic css here
];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.