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.
You will have to create your own implementations Connection
and ConnectionBackend
class and inject it while bootstrapping your app. See sample code below
export class XHRSynchronousConnection implements Connection
{
}
export class XHRSynchronousConnectionBackend implements ConnectionBackend
{
}
You can bootstrap it as follows
bootstrap([provide(ConnectionBackend, {useClass:XHRSynchronousBackend}),
provide(Connection,{useClass:XHRSynchronousConnection}];
You can see the rest of the code in actual source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With