How to add data dynamically to mat-table dataSource?

后端 未结 7 1471
既然无缘
既然无缘 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:15

    You could also use the ES6 spread operator or concat if you are not using ES6+ to assign the dataSource data to a new array.

    In ES6+

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

    ECMAscript version 3+

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

提交回复
热议问题