【发布时间】:2021-05-05 02:57:46
【问题描述】:
我正在尝试使用组件更改 css 变量,但由于某种原因它不起作用,有什么帮助吗?
//work but i dont want to use the property background
<div class="planete" [ngStyle]="{'background': planete.planeteBackgroundColor }"></div>
/* this is what i'd like to do :
.SCSS
$my-var
/*...*/
background: $my-var;
HTLM:
// does not work
<div class="planete" [ngStyle]="{'$my-var': planete.planeteBackgroundColor }">
// second option:
.SCSS
--my-var
/*...*/
background: var(--my-var)
HTLM:
// does not work
<div class="planete" [ngStyle]="{'--my-var': planete.planeteBackgroundColor }">
感谢回复
【问题讨论】:
-
恐怕你不能用 ngStyle 做到这一点。不过还有其他方法:medium.com/angular-in-depth/…
标签: css angular typescript sass