简体   繁体   English

Angular Material 访问主题颜色

[英]Angular Material access theme color

After some searching through SO and GitHub, I'd just like to get a clarification: There is NO WAY to access a theme color (or any other theme feature), for example to set a mat-card color:在通过 SO 和 GitHub 进行一些搜索之后,我只想得到一个澄清:没有办法访问主题颜色(或任何其他主题功能),例如设置垫卡颜色:

  • one cannot access a variable in scss无法访问 scss 中的变量
  • one cannot set a class on the component (like class="mat-purple-with-spots")不能在组件上设置类(例如 class="mat-purple-with-spots")
  • one cannot access the feature through the component API, because most of the time it doesn't expose any theme feature.不能通过组件 API 访问该功能,因为大多数时候它不公开任何主题功能。

There are two options I can see:我可以看到两个选项:

  • one, go through the hairpulling complexity of rolling a custom theme just for that component一,经历为该组件滚动自定义主题的复杂性
  • two, just copy the RGB code and set it in plain dumb CSS on your component二,只需复制 RGB 代码并将其设置在您的组件上的纯哑 CSS 中

Am I missing something?我错过了什么吗?

You can define a custom theme for main colors "accent, primary, warm".您可以为主要颜色“重音、主色、暖色”定义自定义主题。

https://material.angular.io/guide/theming#defining-a-custom-theme https://material.angular.io/guide/theming#defining-a-custom-theme

In other scenario, you could have directives to apply at components what add a custom class with your styles and nested css selectors.在其他情况下,您可以在组件上应用指令,这些指令使用您的样式和嵌套的 css 选择器添加自定义类。

Example:例子:

<mat-card yourDirectiveForCustomStyles></mat-card>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM