0

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?

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.

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.

Has anyone implemented dynamic/user controlled themes/colors in Angular2? Any suggestions for how to approach this?

2
  • What about loading different versions of a stylesheet based on the users selection. The versions would use the same class names but different values/styles. The onclick handler can do something like this stackoverflow.com/a/13735267/4084574 Commented Jun 22, 2017 at 19:09
  • similar to mhatchs link but with some angular code stackoverflow.com/questions/39643042/… Commented Jun 22, 2017 at 19:10

1 Answer 1

1

bro the angular material team has worked in a very cool feature.

https://github.com/angular/material2/blob/master/guides/theming.md

if you want to see a working example https://material.angular.io/ has a theme picker in the navbar.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.