请帮我在Angular2中做一个关于http with synchronous的例子?
我尝试如下:在组件中:
getAllAddress(){
this.addressService.getAllAddress().then(
result => {
this.data = result.list;
this.onChangeTable(this.config, null);
console.log('FIRST');
}
);
console.log('LAST');
}
Run Code Online (Sandbox Code Playgroud)
在服务中:
public getAllAddress(){
return this.__http.get('LOCATION')
.map((res) => {
return res.json()
})
.toPromise();
}
Run Code Online (Sandbox Code Playgroud)
但是控制台显示日志在'FIRST'之前是'最后'.
谢谢.
您必须创建自己的实现Connection和ConnectionBackend类,并在引导应用程序时注入它。请参阅下面的示例代码
export class XHRSynchronousConnection implements Connection
{
}
export class XHRSynchronousConnectionBackend implements ConnectionBackend
{
}
Run Code Online (Sandbox Code Playgroud)
您可以按如下方式引导它
bootstrap([provide(ConnectionBackend, {useClass:XHRSynchronousBackend}),
provide(Connection,{useClass:XHRSynchronousConnection}];
Run Code Online (Sandbox Code Playgroud)
您可以在实际源代码中查看其余代码。
| 归档时间: |
|
| 查看次数: |
2510 次 |
| 最近记录: |