错误错误:无法设置未定义的属性“ paginator”

时间:2018-12-26 17:10:25

标签: angular angular-material

我使用以下示例创建Angular材质表: https://github.com/marinantonio/angular-mat-table-crud。 该示例使用来自@ angular / cdk / table的{DataSource}连接到表。

对于我的项目,我需要将'@ angular / material'中的MatTableDataSource用作表数据连接器,一旦我更改了代码以使用MatTableDataSource,我就不断得到 TypeError:无法设置未定义的属性“ paginator”

我的问题有一个副本 https://stackblitz.com/edit/angular-3rhawr

我做错了什么?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

this.exampleDatabase.getAllIssues()本质上是异步的,可能需要一些时间才能完成。但是ngAfterViewInit将在此之前被调用。并且由于dataSource是在subscribe的{​​{1}}块中设置的,因此会出现错误。

通过将代码从this.exampleDatabase.getAllIssues()的{​​{1}}中移出来解决。像这样:

ngAfterViewInit
  

这里是Working Sample StackBlitz,没有给您的裁判带来错误。