Angular2 HTTP同步

请帮我举一个有关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”。

谢谢。

吉加尔

您将必须创建自己的实现ConnectionConnectionBackend类,并在引导应用程序时注入它。请参阅下面的示例代码

export class XHRSynchronousConnection implements Connection    
 {

 }

export class XHRSynchronousConnectionBackend implements ConnectionBackend
{
}

您可以如下引导

bootstrap([provide(ConnectionBackend, {useClass:XHRSynchronousBackend}),
provide(Connection,{useClass:XHRSynchronousConnection}];

您可以在实际的源代码中看到其余的代码

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章