You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Angular Material中mat-app-background类的背景色变量?

解决Angular Material主题中获取mat-app-background对应颜色值的问题

你当前的SCSS代码拿到#ffffff的原因是,取了背景调色板的索引0(对应调色板中的base色,也就是白色),但mat-app-background类使用的是背景调色板里的background(或default)变体值,而非索引0。

以下是两种正确的实现方式:

方法1:使用mat.get-theme-color直接提取

$background: mat.get-theme-color($theme, 'background', 'default');

方法2:从背景调色板中获取指定键值

$background-palette: map-get($theme, background);
$background: map-get($background-palette, background);

使用任意一种方法后,$background变量都会正确获取到mat-app-background对应的#fafafa颜色值。

内容的提问来源于stack exchange,提问作者MarcS82

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 13:33:10