动态地将数据添加到MatTableDataSource材质角度

问题描述 投票:0回答:1

我想将数据动态添加到MatTableDataSource

https://material.angular.io/components/table/examples

dataSource1 =  new  MatTableDataSource ();

      addRiesgo(model: any) {
        const test: Riesgo = { descripcion: model.descripcionIdentificacion, riesgoinherente: '', riesgoresidual: '' };
      this.dataSource1.data.push(test);

      }

这对我不起作用,无法更新

angular typescript angular-material
1个回答
0
投票

以某种方式直接更新this.dataSource.data将不起作用。您可以尝试这样。

const data = this.dataSource.data;
data.push(test);
this.dataSource.data = data;

这里是工作演示-https://stackblitz.com/edit/angular-qfheuu

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.