I have managed to fix this by making some minor changes to the provider. To allow themes to be changed:
First, modify the generateThemes function in angular-material.js to set generationIsDone = false.
This will allow you to regenerate the themes at a later time.
function generateThemes($injector) {
var styles = $injector.has('$MD_THEME_STYLESHEETS') ? $injector.get('$MD_THEME_STYLESHEETS') : [];
if (styles) {
var $q = $injector.get('$q');
var $http = $injector.get('$http');
var calls = [];
angular.forEach(styles, function(style){
calls.push($http.get(style));
});
$q.all(calls).then(function(responses) {
var css = '';
angular.forEach(responses, function(response) {
css += response.data;
});
generationIsDone = false; // here
generateCss(css);
});
} else {
var css = $injector.has('$MD_THEME_CSS') ? $injector.get('$MD_THEME_CSS') : '';
generationIsDone = false; // here
generateCss(css);
}
}
Second, make the generateThemes() function available as a property on the ThemingService.
You can call it when you have added new themes, to generate their CSS.
ThemingService.$inject = ["$rootScope"];
return themingProvider = {
definePalette: definePalette,
extendPalette: extendPalette,
theme: registerTheme,
setDefaultTheme: function(theme) {
defaultTheme = theme;
},
alwaysWatchTheme: function(alwaysWatch) {
alwaysWatchTheme = alwaysWatch;
},
reload: generateThemes, // here
$get: ThemingService,
_LIGHT_DEFAULT_HUES: LIGHT_DEFAULT_HUES,
_DARK_DEFAULT_HUES: DARK_DEFAULT_HUES,
_PALETTES: PALETTES,
_THEMES: THEMES,
_parseRules: parseRules,
_rgba: rgba
};
Third, to actually make the ThemingProvider available to your controllers, add it to your module as a value.
angular.module("yourModule",['whateverDependencies'])
.config(function($provide, $mdThemingProvider) {
$provide.value('themeProvider', $mdThemingProvider); // now you can inject the provider
})
And finally, where you need it, just call for the value in your controllers:
}).controller('someController', function(themeProvider, $injector) {
themeProvider.theme('someNewTheme').primaryColor('orange').accentColor('pink');
themeProvider.reload($injector);
}