Please help me make an example about http with synchronous in Angular2?
I tried as below: In component:
getAllAddress(){
this.addressService.getAllAddress().then(
result => {
this.data = result.list;
this.onChangeTable(this.config, null);
console.log('FIRST');
}
);
console.log('LAST');
}
In service:
public getAllAddress(){
return this.__http.get('LOCATION')
.map((res) => {
return res.json()
})
.toPromise();
}
But the console show log is 'LAST' before 'FIRST'.
Thanks.