角材料表分页问题角10

时间:2020-08-28 10:45:34

标签: javascript angular angular-material

我正在使用角度材料表进行角度10投影。我已成功添加物料表。 但现在我正尝试在表中添加分页。为此,我在组件中添加了以下代码。

import {MatPaginator} from '@angular/material/paginator';

我在导入上方添加了我的app.module.ts文件。

这是我为html页面添加的用于加载分页的代码

 <mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>

,但是此html标记无效。它发生了错误。

请检查下面的图像。

enter image description here

我的模块 enter image description here

1 个答案:

答案 0 :(得分:0)

如您的IDE所述,该模块不知道该组件。 解决方案是将其添加到您的app.module.ts中(或等效项,具体取决于您在应用程序中的位置)

您应该在应用模块中导入模块MatPaginatorModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MatPaginatorModule } from '@angular/material/paginator';
import { AppComponent } from './app.component';


@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    MatPaginatorModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

请注意,我已直接导入模块而不是组件