.config(CoreTheme)
function CoreTheme($mdThemingProvider) {
$mdThemingProvider.theme('default')
.primaryPalette('blue',{
'default' : '500',
'hue-1' : '900',
'hue-2' : 'A100',
'hue-3' : '400'
})
.accentPalette('green',{
'default' : '600',
'hue-1' : '900',
'hue-2' : 'A100',
'hue-3' : '400'
})
.warnPalette('deep-orange',{
'default' : '500',
});
$mdThemingProvider.alwaysWatchTheme(true)
}
CoreTheme.$inject = ['$mdThemingProvider'];
export default CoreTheme;
module.js
export default angular.module('theme',['ngMaterial']);
controller.js
class ThemeCtrl{
constructor($scope,$rootScope,$mdThemingProvider){
$scope.changeTheme = changeTheme;
function changeTheme(theme_name){
$mdThemingProvider.theme('default').dark()
}
}
}
ThemeCtrl.$inject = ['$scope','$rootScope','$mdThemingProvider'];
export default ThemeCtrl;
我想在这个控制器中 动态改变主题样式 可是注入这个Provider报错!应该怎么做?
我能想到的是(1)可以在.config()中$watch某个变量 来改变主题吗?
Reference question
I just looked at the latest material source code. It seems that there is no reload function. If you want to use the following method, you still need to modify the material source code. If you do not change the source code, please ignore this answer.
You can try it as follows:
1. Modify the source code of material according to the answers in the reference questions
2. In the configure phase, register $mdThemingProvider for controller use
3. Reload the theme in the controller
Configuring of the default theme is done by using the $mdThemingProvider during application configuration.
The official website said, please configure it in configuration.
angular material has already given a theme when generating the page. For example, after md-button is generated, it is md-button md-default-theme. If you want to modify the theme, you can traverse the page and replace md-default-theme with the theme you want, md-dark-theme.
But it’s tiring to do this, right?
So it is best to open a preview in a new window after selecting a theme.
Or have a separate theme page to list what all themes look like. Just have options. After all, previewing the interface on the original website is a very annoying thing.