Angular + Material - How to refresh a data source (mat-table)

前端 未结 23 1367
自闭症患者
自闭症患者 2020-11-28 01:59

I am using a mat-table to list the content of the users chosen languages. They can also add new languages using dialog panel. After they added a language and returned back.

23条回答
  •  爱一瞬间的悲伤
    2020-11-28 03:06

    I think the MatTableDataSource object is some way linked with the data array that you pass to MatTableDataSource constructor.

    For instance:

    dataTable: string[];
    tableDS: MatTableDataSource;
    
    ngOnInit(){
       // here your pass dataTable to the dataSource
       this.tableDS = new MatTableDataSource(this.dataTable); 
    }
    

    So, when you have to change data; change on the original list dataTable and then reflect the change on the table by call _updateChangeSubscription() method on tableDS.

    For instance:

    this.dataTable.push('testing');
    this.tableDS._updateChangeSubscription();
    

    That's work with me through Angular 6.

提交回复
热议问题