You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular9引入MatAutocomplete报exportAs 'matAutocomplete'未找到如何解决

报错根因

问题核心是Angular核心版本与Angular Material、CDK版本不兼容。Angular 9 仅支持 9.x 版本的 @angular/material 和 @angular/cdk,你当前安装的 @angular/material@11.x、@angular/cdk@12.x 跨了多个大版本,会出现指令无法识别、API不匹配的问题。

解决步骤
  • 卸载当前不兼容的依赖包
    执行命令:
    npm uninstall @angular/material @angular/cdk
  • 安装匹配Angular 9的版本
    执行命令:
    npm install @angular/material@9.2.4 @angular/cdk@9.2.4
  • 补充完整模块导入
    除了你已经添加的MatAutocompleteModule、MatFormFieldModule之外,还要确认在组件所属模块的imports数组中加入以下依赖:
    • MatInputModule:提供matInput指令支持
    • ReactiveFormsModule:支持formControl相关语法
    • FormsModule:支持你代码中用到的ngModel双向绑定
      如果你使用了特性模块,需要在特性模块中导入上述依赖,仅在app.module导入不会作用于子模块下的组件。
可选代码修复

你当前模板中[panelWidth]="auto"的绑定是非法的,panelWidth属性接收的是宽度数值或字符串,比如[panelWidth]="300"或者panelWidth="auto",你现在绑定的是mat-autocomplete的组件实例,后续运行时会抛出异常,建议调整为合法的宽度值。


内容的提问来源于stack exchange,提问作者ahmed barbary

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 20:18:02