【发布时间】:2019-09-30 14:08:34
【问题描述】:
我在 Angular 7 项目中使用 SASS (.scss)。它有多个主题。所以我必须为每个主题动态更改全局样式。但我的@if 条件返回 false。
styles.scss:
@import "app/themes/Atlantis/master-style.atlantis.scss";
:root{
--theme: false
}
@if var(--theme) == 'atlantis'{
//@include master-style-atlantis;
html {
background:red; // sample code to check if my @if worked
}
}
我添加了 --theme 带有角度的属性,app.component.ts:
_document = document.querySelector('html');
ngOnInit(): void {
this._document.style.setProperty('--theme', 'atlantis');
}
html 属性设置为style="--theme:atlantis;",但背景颜色没有改变。但是如果我使用
@if var(--theme){
//@include master-style-atlantis;
html {
background:red; // sample code to check if my @if worked
}
}
它有效。如果它是真/假,如果会起作用。但是比较字符串总是返回 false。请帮忙。
【问题讨论】: