it is known that in Angular Material Design you can customize your theme and even create multiple themes and change them on only one click, at least colors. But is it also possible to change a theme including the style of the elements in html and css? So for example I am holding 2 different themes, in theme A the button should be round cornered green while in theme B the button should be cornered blue. So on one click you can switch between those and the Website will apply it?
Asked
Active
Viewed 6,026 times
1
-
Duplicate of: https://stackoverflow.com/questions/25568801/angularjs-switch-css-theme-on-user-selection – Rence May 09 '18 at 13:59
-
1@Sirence I am talking about Angular material. – Chinaedu Onwukwe May 09 '18 at 14:12
-
Did you read throught the first answer in the linked post? "I think it is not a problem of AngularJS. I think your approach should be different. As I know, theme functionality is usually implemented like below. ..." This works universally. – Rence May 09 '18 at 14:16
-
Chinedu(Nwokem), you are the one to make it a material design by adjusting the CSS. Angular does just the switching for you. – Sleek Geek May 09 '18 at 14:16
-
2Looks like OP is asking for Angular, **not** AngularJS. – Edric May 10 '18 at 10:10
-
@Edric correct I am Asking for Angular – Chinaedu Onwukwe May 10 '18 at 10:14
-
Consider looking at the theming guide at the documentation. – Edric May 10 '18 at 14:24
-
You can check my answer at: https://stackoverflow.com/a/72401579/3339907 – shhdharmen May 27 '22 at 07:00
1 Answers
3
Looks like you will want to create a custom theme. Follow the following instructions:
Include Angular Material's theming in the top level of your app's SCSS file.
@import '~@angular/material/theming';
Include the
mat-core
mixin.@include mat-core();
Add some palettes: (See here for the full list of palettes)
$my-app-primary: mat-palette($mat-deeppurple); $my-app-accent: mat-palette($mat-amber, A200, A100, A400); $my-app-theme: mat-light-theme($my-app-primary, $my-app-accent);
Include the theme into the individual theme.
Note: You can also use classes for toggling between the color themes.
.my-app-theme { @include mat-button-theme($my-app-theme); }
You can then reference this with property binding and
ngClass
. (ngClass
,[class.className]
)<button mat-button [ngClass]="{'my-app-theme': isToggled, 'another-app-theme': !isToggled}" (click)="toggleState()" color="primary">Toggle theme</button>
isToggled: boolean; toggleState() { this.isToggled = !this.isToggled; }
Consider looking at the Theming guide on Angular Material.

Edric
- 24,639
- 13
- 81
- 91