如何在angular配置中使用变量

时间:2015-05-11 08:05:30

标签: javascript angularjs

我正在尝试在角度代码的配置中动态设置Angular MD主题的颜色。但我似乎无法改变它...我希望primaryPalette在由themeChangerAdjustment触发器更改时更改为变量颜色。

var color = red;

angular.module('myApp', ['ngResource', 'ui.router', 'ui.bootstrap', 'ngMaterial'])
.config(['$mdThemingProvider', function($mdThemingProvider) {
    $mdThemingProvider.theme('default').primaryPalette(color).accentPalette('orange');
}])

.run(['$log','$rootScope', 'themeChangerService', function($log,$rootScope, themeChangerService){
    $rootScope.$on('themeChangerAdjustment', function(){
        alert(themeChangerService.themes.color);
        color = themeChangerService.themes.color; //works
    });
    themeChangerService.prepForAdjustment(1);
}]);

1 个答案:

答案 0 :(得分:1)

您可以声明可在配置块see doc

中访问的提供程序
class MissingMethodException(BaseException):
    def __init__(self, message):
        super(MissingMethodException, self).__init__(message)

class BaseModel(models.Model):
    name = models.CharField(max_length=100)
    def __unicode__(self):
        return self.name
    class Meta:
        abstract=True
    def start(self):
        #this will only throw an exception when called
        raise MissingMethodException("Method start is missing") 

请参阅JSFiddle demo here