请帮我举一个有关Angular2中带有同步HTTP的示例吗?
我尝试如下:在组件中:
getAllAddress(){
this.addressService.getAllAddress().then(
result => {
this.data = result.list;
this.onChangeTable(this.config, null);
console.log('FIRST');
}
);
console.log('LAST');
}
使用中:
public getAllAddress(){
return this.__http.get('LOCATION')
.map((res) => {
return res.json()
})
.toPromise();
}
但是控制台显示日志在“ FIRST”之前是“ LAST”。
谢谢。
您将必须创建自己的实现Connection
和ConnectionBackend
类,并在引导应用程序时注入它。请参阅下面的示例代码
export class XHRSynchronousConnection implements Connection
{
}
export class XHRSynchronousConnectionBackend implements ConnectionBackend
{
}
您可以如下引导
bootstrap([provide(ConnectionBackend, {useClass:XHRSynchronousBackend}),
provide(Connection,{useClass:XHRSynchronousConnection}];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句