首页 > 解决方案 > 导入 MatTabChangeEvent 时出错

问题描述

我正在尝试使用角度材料库。我在 package.json 中添加了 @angular/material 的依赖项,如下所示

"@angular/animations": "^5.0.0",
"@angular/cdk": "^6.0.0",
"@angular/material": "^5.2.5",

当我使用

import { MatTabChangeEvent } from '@angular/material';

它在编译时抛出错误

ERROR in [at-loader] ./node_modules/@angular/material/stepper/typings/stepper.d.ts:28:5
TS2416: Property '_stepHeader' in type 'MatStepper' is not assignable to the same property in base type 'CdkStepper'.
Type 'QueryList<ElementRef>' is not assignable to type 'QueryList<FocusableOption>'.
Type 'ElementRef' is not assignable to type 'FocusableOption'.
  Property 'focus' is missing in type 'ElementRef'.

除了导入行之外,我没有添加任何与角度材料相关的代码。

标签: angular-materialangular5angular-cdk

解决方案


您需要确保拥有相同版本的 Angular CDK 和 Material,以及 Angular Material 和 CDK 的 Angular 版本。

在这种情况下,将所有依赖项升级到 Angular 6:

npm install @angular/cdk @angular/material

或者:

npm update

推荐阅读