【发布时间】:2020-11-03 11:26:56
【问题描述】:
我有一个使用 Angular Material 的 Angular 9 应用程序,它有 2 个主题(深色和浅色)。它们在 style.scss 文件中是这样定义的:
$rasd-dark-text-color: mat-palette($mat-grey, 300);
$rasd-light-text-color: mat-palette($mat-grey, 800);
.rasd-dark {
--text-color: #{mat-color($rasd-dark-text-color)};
}
.rasd-light {
--text-color: #{mat-color($rasd-light-text-color)};
}
为了给应用设置主题,我只是将它设置为body元素的一个类:
<body class="mat-typography rasd-dark">
<app-root></app-root>
</body>
我有一个小的 Angular 组件,它需要从 --test-color 中获取值作为 Hex color,这取决于哪个(应用深色或浅色主题) body 元素上)。
export class ChartComponent implements OnInit {
textColor: string;
ngOnInit(): void {
// (!!!) How can I set the value for textColor from --test-color in SCSS?
// e.g: after setting, the value of textColor is #001100
}
}
【问题讨论】:
标签: javascript angular sass angular-material