How to pass data to material table data source dynamically

后端 未结 1 1191
醉酒成梦
醉酒成梦 2021-01-21 10:21

I want to pass the dynamic data to material table. I show my code:

parent.component.html

1条回答
  •  失恋的感觉
    2021-01-21 11:05

    you can use it like this: create a new DataSource based on a copy of the data (for immutability)

    this.dataSource = new MatTableDataSource([...<[whatever incoming data]>);
    

    try this (for your case)

    this.feedsService.getFeedsByVin(this.vin).subscribe((data) => {
            this.feedsOverviewData = [...data];
          });
    

    (similar setup for ngOnInit)

     ngOnChange() {
        console.log(this.feedsOverviewData);
        this.dataSource = new MatTableDataSource(this.feedsOverviewData);
      }
    

    the subscribe works in its own async process with the data only available there. angular does some things behind the scenes to make this work.

     
    

    0 讨论(0)
提交回复
热议问题