angular/material2 中的深色主题不是深色

Dark-theme in angular/material2 is not dark

我正在与 angular/material2 合作,我正在尝试获得深色主题。 按照 https://material.angular.io/guide/theming 的文档,我定义了我的自定义 theme.scss 如下:

$dark-primary: md-palette($md-pink, 700, 500, 900);
$dark-accent:  md-palette($md-blue-grey, A200, A100, A400);
$dark-warn:    md-palette($md-deep-orange);

$dark-theme: md-dark-theme($dark-primary, $dark-accent, $dark-warn);

@include angular-material-theme($dark-theme);

主色、重音色和警告色按照我的自定义主题中的定义显示,但我没有看到深色主题(即黑色背景和前景色相应更改)。

example provided 和文档中,我看到背景已通过 css class 设置,但这不是我期望的行为; dark-theme 在我看来是一个特定的 "kind" 主题,具有适当的自动化水平。

我错了吗?谁能帮我澄清这个问题?

绝对是我错了!!! 深色主题有效……但仅当在 md- 选择器(例如 md-card 内时才有效。 设置正文背景颜色只能使用 css.

来自文档:

Finally, if your app's content is not placed inside of a mat-sidenav-container element, you need to add the mat-app-background class to your wrapper element (for example the body).

因此,如果您不使用 mat-sidenav-container 组件,则需要将 Angular Material 2 背景 class 添加到您的 HTML body 赞:

<body class="mat-app-background">