我正在尝试在一个组件中使用 mat-chip。在我升级到 Angular 15 之前,我的代码是可以工作的。
我已经导入了该模块,这似乎是一个常见的错误。
我认为我根据文档已经包含了所有必要的内容。
非常感谢您的帮助。谢谢!
错误信息如下:
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.
版本信息如下:
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
我的 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` { }
我的组件:
`<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>`
和 component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'chips-example',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent
{
}
app.modules.ts
文件中,当你导出MatChipsModule
时会发生什么? - Ali Celebiimports
中是否也包括了import { BrowserModule } from "@angular/platform-browser";
中的BrowserModule
?并且重新启动服务器? - W.S.