如何从角度材料中获取主要的深色,或者我们可以在角度材料中使用哪些颜色变量?

Ket*_*Wtf 3 angular-material angular

您好,我们如何使用有角材料的原色深色?我已经使用过color="p-dark" ,但不起作用。

我们如何获取材质颜色工具定义的深色?我想使用以下帮助网站定义的深色:

https://material.io/resources/color/#!/?view.left=1&view.right=0&primary.color=FFF9C4

我们必须在自定义主题中定义它吗?

或者有人可以分享我们可以与角度材料一起使用的所有颜色变量吗?

Arn*_*lle 7

我不知道是否可以直接使用预定义的 CSS 类来完成此操作,但以下是如何在 SCSS 中执行此操作。

我想作为一个起点,您的主题是这样定义的:

我的材料主题.scss

[...]
$my-app-theme: mat.define-light-theme($app-primary, $app-accent, $app-warn);
Run Code Online (Sandbox Code Playgroud)

然后,在您的组件 SCSS 中:

我的组件.css

@use 'sass:map';
@use '@angular/material' as mat;
@import 'path/to/my-material-theme';


$color-config: mat.get-color-config($my-app-theme);

// get the chosen palette : primary, accent, warn
$primary-palette: map.get($color-config, 'primary');

.my-class {
  color: mat.get-color-from-palette($primary-palette, 700);
}
Run Code Online (Sandbox Code Playgroud)

更多信息: