Angular 19中'mat-chip-list'报NG8001错误,是否为Material 19的Bug?
解决Angular Material 19中'mat-chip-list'报NG8001错误的问题
这不是Angular Material 19的Bug,而是官方在v19版本中对Chip组件做的破坏性API变更:原mat-chip-list组件已被废弃,取而代之的是mat-chip-set组件。
修复步骤
直接将模板中的<mat-chip-list>标签替换为<mat-chip-set>即可,组件的导入部分无需修改(MatChipsModule已经包含新的mat-chip-set组件)。
修改后的组件代码
import { Component } from '@angular/core'; import { MatChipsModule } from '@angular/material/chips'; @Component({ selector: 'app-test-chips', standalone: true, imports: [MatChipsModule], template: ` <mat-chip-set aria-label="Fish selection"> <mat-chip>One fish</mat-chip> <mat-chip>Two fish</mat-chip> <mat-chip color="primary" selected>Primary fish</mat-chip> </mat-chip-set> ` }) export class TestChipsComponent { }
补充说明
如果需要临时兼容旧版写法,可以在组件或模块中启用兼容模式,但官方强烈建议直接迁移到新组件,因为mat-chip-list会在后续版本中彻底移除:
// 在组件或模块中添加配置 providers: [ { provide: MAT_CHIPS_COMPATIBILITY_MODE, useValue: true } ]
内容的提问来源于stack exchange,提问作者Ajay Kulkarni
相关产品推荐
相关产品推荐

