我想在我的角度应用程序中使用材料表。我浏览了材料的官方文档以使用该表。但我在这方面遇到了几个错误。
这是我的组件代码:
<div class="container">
<div class="header">
<span style="font-size: 20px;"
>Manage <sub style="font-size: 12px;">Brands</sub></span
>
</div>
<hr style="margin: 10px 0;" />
<button class="btn btn-primary">Add Brand</button>
<br />
<hr />
<cdk-table [dataSource]="dataSource">
<!-- Position Column -->
<ng-container cdkColumnDef="position">
<th cdk-header-cell *cdkHeaderCellDef> No. </th>
<td cdk-cell *cdkCellDef="let element"> {{element.position}} </td>
</ng-container>
<!-- Name Column -->
<ng-container cdkColumnDef="name">
<th cdk-header-cell *cdkHeaderCellDef> Name </th>
<td cdk-cell *cdkCellDef="let element"> {{element.name}} </td>
</ng-container>
<!-- Weight Column -->
<ng-container cdkColumnDef="weight">
<th cdk-header-cell *cdkHeaderCellDef> Weight </th>
<td cdk-cell *cdkCellDef="let element"> {{element.weight}} </td>
</ng-container>
<!-- Symbol Column -->
<ng-container cdkColumnDef="symbol">
<th cdk-header-cell *cdkHeaderCellDef> Symbol </th>
<td cdk-cell *cdkCellDef="let element"> {{element.symbol}} </td>
</ng-container>
<cdk-header-row *cdkHeaderRowDef="displayedColumns"></cdk-header-row>
<cdk-row *cdkRowDef="let row; columns: displayedColumns;"></cdk-row>
</cdk-table>
</div>
这是我的导入文件夹:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HeaderComponent } from './header/header.component';
//======================================== material modules==========================
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field'
import { MatDividerModule } from '@angular/material/divider'
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatListModule } from '@angular/material/list';
import { CdkTableModule } from '@angular/cdk/table';
import { DataSource } from '@angular/cdk/table'
// ==================================================================================
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { LoginPageComponent } from './login-page/login-page.component';
import { ForgotPasswordPageComponent } from './forgot-password-page/forgot-password-page.component';
import { HomePageComponent } from './home-page/home-page.component';
import { DisplayModule } from './display/display-page.module'
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
LoginPageComponent,
ForgotPasswordPageComponent,
HomePageComponent,
],
imports: [
BrowserModule, AppRoutingModule, BrowserAnimationsModule, MatButtonModule,
MatIconModule, MatToolbarModule,
MatInputModule, MatFormFieldModule, FormsModule, ReactiveFormsModule,
MatDividerModule, MatCheckboxModule, MatSidenavModule, MatListModule,
DisplayModule, CdkTableModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
ERROR in src/app/display/brands/brands.component.html:12:3 - error NG8001: 'cdk-table' is not a
known element:
1. If 'cdk-table' is an Angular component, then verify that it is part of this module.
2. If 'cdk-table' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of
this component to suppress this message.
12 <cdk-table [dataSource]="dataSource">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app/display/brands/brands.component.ts:42:16
42 templateUrl: './brands.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component BrandsComponent.
src/app/display/brands/brands.component.html:12:14 - error NG8002: Can't bind to 'dataSource' since
it isn't a known property of 'cdk-table'.
1. If 'cdk-table' is an Angular component and it has 'dataSource' input, then verify that it is part
of this module.
2. If 'cdk-table' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of
this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
12 <cdk-table [dataSource]="dataSource">
~~~~~~~~~~~~~~~~~~~~~~~~~
src/app/display/brands/brands.component.ts:42:16
42 templateUrl: './brands.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component BrandsComponent.
我已经导入了所有必需的模块并使用了最新的材料和角度版本。我仍然无法理解。谁能建议我如何摆脱这个错误?