Angular2材料表错误

时间:2017-09-22 08:27:01

标签: angular angular-material2

我有一个使用Angular2的角度材质表。

我的数据被正确检索,据我所知,我的表看起来还不错。我推迟了表的初始化,直到检索到数据以确保不是问题。但是,我遇到了这个问题:

Cannot read property 'diff' of undefined

我的HTML如下:

`<div *ngIf="repacksReturned">
     <md-table #table [dataSource]="openRepacks">
         <ng-container cdkColumnDef="ID">
             <md-header-cell *cdkHeaderCellDef> ID </md-header-cell>
             <md-cell *cdkCellDef="let row">{{row.ID}}</md-cell>
         </ng-container>

         <md-header-row *cdkHeaderRowDef="displayedColumns"></md-header-row>
         <md-row *cdkRowDef="let row; columns: displayedColumns;"></md-row>
     </md-table>
</div>`

我的类型脚本如下:

export class JobComponent implements OnInit {
    openRepacks = new Array<RepackRequest>();
    repacksReturned = false;
    displayedColumns: ['ID'];

    constructor(private repackService: RepackService) { }

    ngOnInit() {
        this.getOpenRepacks();
    }

    getOpenRepacks(): void {
        this.repackService.GetOpenRepacks()
                  .subscribe((data: RepackRequest[]) => {
                    console.log(data);
                    this.openRepacks = data;
                    this.repacksReturned = true;
                  });
    }
}

我环顾四周,无法找到解决此问题的任何内容。

提前致谢!

修改

来自控制台的Stacktrace

ERROR TypeError: Cannot read property 'diff' of undefined
at CdkRowDef.webpackJsonp.../../../cdk/@angular/cdk/table.es5.js.BaseRowDef.getColumnsDiff (table.es5.js:53)
at table.es5.js:533
at Array.forEach (<anonymous>)
at QueryList.webpackJsonp.../../../core/@angular/core.es5.js.QueryList.forEach (core.es5.js:5534)
at MdTable.webpackJsonp.../../../cdk/@angular/cdk/table.es5.js.CdkTable._renderUpdatedColumns (table.es5.js:532)
at MdTable.webpackJsonp.../../../cdk/@angular/cdk/table.es5.js.CdkTable.ngAfterContentChecked (table.es5.js:493)
at callProviderLifecycles (core.es5.js:11199)
at callElementProvidersLifecycles (core.es5.js:11177)
at callLifecycleHooksChildrenFirst (core.es5.js:11161)
at checkAndUpdateView (core.es5.js:12266)

0 个答案:

没有答案