Search code examples
jsonangularng2-smart-table

local json file and ng2-smart-table


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>

Solution

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

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