0

How to load the local json file and display data in ng2-smart-table?

This is my current code for retrieve the data from the local json file:

public getList() {
    return this.http.get('./assets/data/line-items.json')
        .toPromise()
        .then(response => response.json())
        .then(json => {
            console.log('data', json.items);
            return json.items;
        });
}

and I want to pass all the data to [source] in ng2-smart-table

<ng2-smart-table [settings]="settings" [source]="data"></ng2-smart-table>
Jim
  • 91
  • 2
  • 12

1 Answers1

1

getList return a promise, so you have to do this :

 this.getList().then(data=>{
   this.data = data;

});
El houcine bougarfaoui
  • 35,805
  • 9
  • 37
  • 37