Angular 2 smart table dynamic data don't load

Viewed 1414

I use Angular 6 and smart table : https://akveo.github.io/ng2-smart-table/#/.

Everything works just fine, till I try to change data from static to dynamic :

This works and shows everything in 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);

and this doesnt :

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);

Outputs are equal : enter image description here

What's wrong with that and maybe somebody was facing this problem ?

1 Answers

I did not work with Firebase or ng2-smart-table before, but it should work if you move your loading of the data-source within the subscribe.

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