Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度材质分页器未定义_Angular_Typescript_Angular Material_Paginator - Fatal编程技术网

Angular 角度材质分页器未定义

Angular 角度材质分页器未定义,angular,typescript,angular-material,paginator,Angular,Typescript,Angular Material,Paginator,我使用角材料(MatTable、MatPaginator)。 当我登录到应用程序并加载组件视图时,我的浏览器调试器中出现以下错误: ERROR TypeError: "_this._paginator is undefined; can't access its "pageIndex" property" ExampleDataSource http://localhost:4200/main.js:1446 __tryOrUnsub http://localhost:

我使用角材料(MatTable、MatPaginator)。 当我登录到应用程序并加载组件视图时,我的浏览器调试器中出现以下错误:

    ERROR TypeError: "_this._paginator is undefined; can't access its "pageIndex" property"

    ExampleDataSource http://localhost:4200/main.js:1446
    __tryOrUnsub http://localhost:4200/vendor.js:160732
    next http://localhost:4200/vendor.js:160670
    _next http://localhost:4200/vendor.js:160603
    next http://localhost:4200/vendor.js:160578
    _subscribe http://localhost:4200/vendor.js:159751
    _trySubscribe http://localhost:4200/vendor.js:159963
    _trySubscribe http://localhost:4200/vendor.js:160384
我的目标是消除这个错误

由于有太多的代码可能导致此错误,请在我的Github上查看我的组件:

问题必须位于表.component.ts中


提前非常感谢

Paginator用@ViewChild标记,因此在调用ngAfterViewInit()之前不会加载。但是,您将构造新ExampleDataSource的实例放在loadData()中,该实例在ngOnInit中调用但根据钩子方法的顺序,ngOnInit()将在ngAfterViewInit()之前调用。在ngAfterViewInit()之前至少调用过两次!因此,将这个.loadData()放入ngAfterViewInit,并将其放在顶部

dataSource: ExampleDataSource;

删除依赖于此的任何内容。paginator将改为位于ngAfterViewInit中。

angular版本?@angular/cli:“~6.1.5”,Stackblitz在这种情况下会有所帮助!谢谢你的评论。我也可以成功地构建它。我也没有收到ng live服务器的错误。但是我的浏览器调试器显示了上面提到的错误。一切正常,我只是不想有这个错误:)。我想我必须在ngAfterViewInit()中初始化分页器,但我真的不知道如何初始化。看,嗯,找官方文件!