How to add data dynamically to mat-table dataSource?

后端 未结 7 1440
既然无缘
既然无缘 2020-12-08 06:39

I have data streaming from backend and i see it printing in console now i am trying to push event to dataSource its throwing error dataSource is not defined. Ca

7条回答
  •  时光说笑
    2020-12-08 07:07

    I have found a solution for this problem, basically if you do:

    this.dataSource.data.push(newElement); //Doesn't work

    But if you replace the complete array then it works fine. So your final code must be :

    this.socket.on('newMessage', function(event) {
        const data = this.dataSource.data;
        data.push(event);
        this.dataSource.data = data;
    });
    

    You can see the issue here -> https://github.com/angular/material2/issues/8381

提交回复
热议问题