angular-material - 导入 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 CDK 和 Material,以及 Angular Material 和 CDK 的 Angular 版本。
在这种情况下,将所有依赖项升级到 Angular 6:
npm install @angular/cdk @angular/material
或者:
npm update
推荐阅读
- c# - 使用 C# 中的参数从 JQuery 调用 WebMethod
- python - 列表理解与将生成器表达式传递给列表
- ios - iOS 12 上的 PWA 不再与 Safari 共享 Service Worker 缓存?
- android - 检查服务是否已在运行
- node.js - 错误 TS2305:模块“/node_modules/rxjs/Rx”没有导出的成员“可订阅”
- wpf - WPF X:名称导致类型名称“ViewModel”编译错误
- android - 无法在两个不同的微调器 android 中设置单个数组列表数据
- python - 获取 Numpy MaskedArray 的最小值和最大值引发 AttributeError
- c# - 在启动时启动 Windows 窗体程序
- java - Spring 的 @Qualifier 不起作用