Jim
Jim

Reputation: 91

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>

Upvotes: 0

Views: 558

Answers (1)

El houcine bougarfaoui
El houcine bougarfaoui

Reputation: 37343

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

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

});

Upvotes: 1

Related Questions