Dynamically loading a material theme in angular

前端 未结 6 1932
广开言路
广开言路 2020-12-10 07:55

I\'m building an Angular application using Angular Material. One of the first steps in the application is that the user logs in. Next, the system loads from the backend the

6条回答
  •  粉色の甜心
    2020-12-10 08:22

    .config(function ($mdThemingProvider, $provide) {
         $provide.value('$mdThemingProvider', $mdThemingProvider);
    });
    

    Now you can inject $mdTheming and $mdThemingProvider in your controller and insert the code below in your controller.

    $mdThemingProvider.theme().primaryPalette().accentPalette(>accent_color>);
    $mdTheming.generateTheme();
    

    If you want this to be your default theme, then:

    $mdThemingProvider.setDefaultTheme();
    

    or use md-theme="" in HTML.

    PS: Works with Angular Material 1.1 and above.

提交回复
热议问题