【问题标题】:Angular 2 smart table dynamic data don't loadAngular 2智能表动态数据不加载
【发布时间】:2019-02-05 13:27:20
【问题描述】:

我使用 Angular 6 和智能表: https://akveo.github.io/ng2-smart-table/#/

一切正常,直到我尝试将数据从静态更改为动态:

这有效并显示了表格中的所有内容:

  source: LocalDataSource = new LocalDataSource();
 data = [{
    id: 1,
    Customer: 'UK LTD',
    Name: 'Mark Poll',
    Code: '84615A',
    PostalCode: 'U48K46',
    Date: '09/19/2018',
  },
  ];
  this.source.load(this.data);

这不是:

data1 = [];
      source: LocalDataSource = new LocalDataSource();
      getArray() {
        this.afDatabase.list('/imones').valueChanges().subscribe(res => {
          this.data1 = res;
          console.log(this.data1)
        })
      }

          this.source.load(this.data1);

输出相等:

这有什么问题,也许有人正面临这个问题?

【问题讨论】:

  • 它不起作用,因为您在第二个示例中的数据加载是异步的。
  • 那么,我不应该订阅它吗?如果你熟悉firebase,能给我举个例子吗?

标签: javascript angular typescript firebase ng2-smart-table


【解决方案1】:

我之前没有使用过 Firebase 或 ng2-smart-table,但如果您在订阅中移动数据源的加载,它应该可以工作。

source: LocalDataSource = new LocalDataSource();
getArray() {
   this.afDatabase.list('/imones').valueChanges().subscribe(res => {
      this.source.load(res);
   })
}

【讨论】:

    猜你喜欢
    • 2017-08-25
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 2018-02-06
    • 1970-01-01
    • 2016-09-17
    相关资源
    最近更新 更多