【问题标题】:Dynamically add data to MatTableDataSource Material Angular动态添加数据到 MatTableDataSource Material Angular
【发布时间】:2019-11-22 16:17:17
【问题描述】:

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

      }

这对我不起作用,不更新

【问题讨论】:

  • 没有更新............
  • 你能显示所有代码吗?您在模板或 TS 上调用 addRiego() 的位置

标签: angular typescript angular-material


【解决方案1】:

不知何故直接更新 this.dataSource.data 是行不通的。你可以这样试试。

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

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

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 2019-08-02
    • 2020-08-24
    • 2018-03-28
    • 1970-01-01
    • 2020-06-10
    相关资源
    最近更新 更多