[英]'mat-chip-list' is not a known element
I'm trying to use mat-chip in a component.我正在尝试在组件中使用 mat-chip。 My code used to work before I upgraded to Angular 15在我升级到 Angular 15 之前,我的代码曾经可以工作
I am importing the module, which seems to be a common mistake我正在导入模块,这似乎是一个常见的错误
I think I've included everything according to the docs.我想我已经根据文档包含了所有内容。
Assistance much appreciated.非常感谢协助。 Thanks谢谢
The error is:错误是:
Error: src/app/app.component.html:1:1 - error NG8001: 'mat-chip-list' is not a known element:
1. If 'mat-chip-list' is an Angular component, then verify that it is part of this module.
2. If 'mat-chip-list' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
1 <mat-chip-list>
~~~~~~~~~~~~~~~
src/app/app.component.ts:5:16
5 templateUrl: './app.component.html',
~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component AppComponent.
The version info is:版本信息是:
Angular CLI: 15.0.0-rc.3
Node: 16.14.0
Package Manager: npm 9.1.1
OS: linux x64
Angular: 15.0.0-rc.3
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1500.0-rc.3
@angular-devkit/build-angular 15.0.0-rc.3
@angular-devkit/core 15.0.0-rc.3
@angular-devkit/schematics 15.0.0-rc.3
@angular/cdk 15.0.0-rc.2
@angular/material 15.0.0-rc.2
@schematics/angular 15.0.0-rc.3
rxjs 7.5.7
typescript
4.8.4
My app.modules.ts:我的 app.modules.ts:
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { MatChipsModule } from '@angular/material/chips';
@NgModule({
declarations: [
AppComponent
],
imports: [
MatChipsModule
],
exports: [
],
providers: [
],
bootstrap: [AppComponent],
entryComponents: [
]
})
export class AppModule` { }
and my component:和我的组成部分:
`<mat-chip-list>
<mat-chip>
Dog one
</mat-chip>
<mat-chip color="primary">
Dog two
</mat-chip>
<mat-chip color="accent">
Dog three
</mat-chip>
</mat-chip-list>`
and component.ts:和组件.ts:
import { Component } from '@angular/core';
@Component({
selector: 'chips-example',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent
{
}
Angular Material v15 switches to MDC based components, which have some breaking changes. Angular Material v15 切换到基于 MDC 的组件,这些组件有一些重大变化。 At the time when you posted the question, Angular 15 didn't have a stable release yet, but now it has.在您发布问题时,Angular 15 还没有稳定版本,但现在有了。
There is a migration guide for chips , which states that the <mat-chip-list>
was removed and replaced by three alternative components, most probably you want to use <mat-chip-listbox>
.有一个chips 的迁移指南,其中指出<mat-chip-list>
已被删除并由三个替代组件替换,很可能您想使用<mat-chip-listbox>
。
Alternatively, you can use the "old" chips implementation in v15 by importing MatLegacyChipsModule
.或者,您可以通过导入MatLegacyChipsModule
在 v15 中使用“旧”芯片实现。
trying including BrowserModule,BrowserAnimationsModule in your import array and define the import at the top.尝试在导入数组中包含 BrowserModule、BrowserAnimationsModule 并在顶部定义导入。 eg.例如。 import { BrowserModule } from '@angular/platform-browser' and import { BrowserAnimationsModule } from '@angular/platform-browser/animations';从'@angular/platform-browser'导入{BrowserModule}并从'@angular/platform-browser/animations'导入{BrowserAnimationsModule};
Alternatively, You can try mat-chip-grid with mat-chip-row.或者,您可以尝试 mat-chip-grid 和 mat-chip-row。 It solved my problem.它解决了我的问题。
https://material.angular.io/components/chips/overview#text-entry https://material.angular.io/components/chips/overview#text-entry
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.