NullInjectorError:没有提供 HighContrastModeDetector

anu*_*jan 7 angular angular8

我正在为我的项目使用 Angular 8,使用节点版本 10.15.3(曾尝试使用其他版本,包括最新的 12.31.1)。这在 MAC 上工作正常,但在 Windows 上运行时,它在浏览器上停止并出现错误

NullInjectorError: "StaticInjectorError(AppModule)[MatCommonModule -> HighContrastModeDetector]: 
  StaticInjectorError(Platform: core)[MatCommonModule -> HighContrastModeDetector]: 
    NullInjectorError: No provider for HighContrastModeDetector!"
Run Code Online (Sandbox Code Playgroud)

这是否与我的硬件有关(它是如何相关的)?

Dex*_*ter 22

问题与 Node 版本无关。这是由于不兼容的 Angular Material 和 Angular 版本。对于 angular 8,您需要 angular material 版本 8.2.3。从您的项目根目录运行以下命令。

npm i --save @angular/cdk@8.2.3 @angular/material@8.2.3
Run Code Online (Sandbox Code Playgroud)

有关找出兼容的角度和角度材料版本的步骤,请参阅此 SO 帖子的答案


Evg*_*eev 10

当我有一个来自 的模块时,我在 StackBlitz 上发生了这种情况@angular/material,但没有import { BrowserModule } from '@angular/platform-browser';

在这种情况下,解决方案是添加BrowserModule.


und*_*god 2

就我而言,@angular/cdk版本导致了错误。

将其设置为打开github:angular/cdk-builds,然后运行解决了问题^8.1.4package.jsonnpm install

在此输入图像描述