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

时间:2019-11-22 16:17:17

标签: angular typescript angular-material

我想动态地将数据添加到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);

      }

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

1 个答案:

答案 0 :(得分:0)

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

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

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

希望这会有所帮助。