2017-10-11 79 views
0

我正在使用md-tabs并希望将背景颜色从默认浅灰色设置为白色。在我的模块,我定义的:

var module = angular.module('myMod', ['ngMaterial']); 
module.config(function ($mdThemingProvider) { 
    $mdThemingProvider.backgroundPalette('white'); 
}); 

当我开始我的申请,我得到以下错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module myMod due to: 
TypeError: $mdThemingProvider.backgroundPalette is not a function 

我采用了棱角分明材料1.1.5版本。

有关此错误发生的原因的任何想法?提前Thanx。

回答

0

你必须让你想从供应商首先要修改的主题:

$mdThemingProvider.theme('default') 
    .backgroundPalette('white'); 
+0

我也试过,但后来我得到了错误“未捕获TypeError:无法读取未定义的属性'600'。显然,我必须先定义白色。那可能吗? – YourReflection

+0

似乎白色不是预先定义的颜色之一,所以看起来很可能 –

+0

https://material.angularjs.org/latest/Theming/03_configuring_a_theme似乎有你在之后的信息 –

0

我知道了。在模块中,必须为所有色调定义白色:

var module = angular.module('myMod', ['ngMaterial']); 
module 
.config(function ($mdThemingProvider) { 
    $mdThemingProvider.definePalette('white', { 
     '50': 'ffffff', 
     '100': 'ffffff', 
     '200': 'ffffff', 
     '300': 'ffffff', 
     '400': 'ffffff', 
     '500': 'ffffff', 
     '600': 'ffffff', 
     '700': 'ffffff', 
     '800': 'ffffff', 
     '900': 'ffffff', 
     'A100': 'ffffff', 
     'A200': 'ffffff', 
     'A400': 'ffffff', 
     'A700': 'ffffff' 
    }); 
    $mdThemingProvider 
     .theme('default') 
     .backgroundPalette('white'); 
}); 

而且颜色必须在元素的相应html中设置。在我的情况下:

<md-content md-colors="{'background-color': 'white'}">...</md-content>