Angular 12 警告:由于选择器错误而跳过 1 条规则::hos​​t-context(.isDarkTheme) -> 不匹配的伪类:host-context

Dri*_*ify 5 css sass angular-material angular

我在用着.isDarkTheme在我的 Angular 应用程序上用作类<body>。然后,我使用此类作为参考来使用应用程序的深色或浅色主题。

我们正在努力过渡到 Angular 12,在进行构建时,我们收到以下警告:

Warning: 1 rules skipped due to selector errors:
  :host-context(.isDarkTheme) -> unmatched pseudo-class :host-context
Run Code Online (Sandbox Code Playgroud)

环境

  • 更新到 Angular 12
  • 有角材料的使用

我们正在.isDarkTheme使用:host-context在 SCSS 文件中以不同的方式

使用内联类:

:host-context(.isDarkTheme) .container {
    background-color: rgba($mat-dark-color, var(--theme-form-background-opacity, $mat-form-alpha));
  }
Run Code Online (Sandbox Code Playgroud)

以及嵌套类:

:host-context(.isDarkTheme) {
  .bg,
  .select,
  .bar {
    background-color: var(--theme-background-background, $mat-light-color);
  }
}
Run Code Online (Sandbox Code Playgroud)

该警告似乎是全局性的,与特定文件无关,那么是否有一种方法不正确?或者是:host-context不是一个好的做法?

如果您有疑问,或者我的问题不够详细,请告诉我。在此先感谢您的帮助 :)