问题描述
我有一个 angular 2 应用程序,我想在其中实现用户从预定调色板列表中选择他们的颜色主题的能力.当他们选择一个主题时,所有相关的颜色、背景颜色等实例都将从主题调色板更改为相应的新颜色.有什么方法可以从 Angular 控制器实现这一点吗?
I have an angular 2 application in which I'd like to implement the ability for a user to choose their color theme from a list of predetermined color palettes. When they select a theme, ALL relevant instances of color, background-color, etc will be changed to the corresponding new color from the theme palette. Is there any way to implement this from an Angular controller?
我知道您可以使用 [class.className] 或 [ngClass] 有条件地向特定元素添加类,但显然在大型应用程序中必须单独更改每个属性的样式是不切实际的.
I know that you can conditionally add classes to specific elements using [class.className] or [ngClass] but obviously it is not practical to have to change the styles individually on every single attribute in a large application.
特定用例:附加到更新主题"按钮的(单击)侦听器由用于更改 .css 文件中的 css 颜色值的控制器函数处理.
Specific use case: (click) listener attached to an "Update Theme" button is handled by a controller function used to change the css color values in .css file.
是否有人在 Angular2 中实现了动态/用户控制的主题/颜色?关于如何解决这个问题的任何建议?
Has anyone implemented dynamic/user controlled themes/colors in Angular2? Any suggestions for how to approach this?
推荐答案
angular material 团队开发了一个非常酷的功能.
bro the angular material team has worked in a very cool feature.
https://github.com/angular/material2/blob/master/guides/theming.md
如果你想看一个工作示例 https://material.angular.io/ 有一个导航栏中的主题选择器.
if you want to see a working example https://material.angular.io/ has a theme picker in the navbar.
这篇关于Angular2:动态更新 CSS 中的所有颜色分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!