加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2 http同步

发布时间:2020-12-17 18:08:58 所属栏目:安全 来源:网络整理
导读:请帮我在Angular2中做一个关于http with synchronous的例子? 我试过如下: 在组件中: getAllAddress(){ this.addressService.getAllAddress().then( result = { this.data = result.list; this.onChangeTable(this.config,null); console.log('FIRST'); }
请帮我在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');
}

在服务中:

public getAllAddress(){
    return this.__http.get('LOCATION')
    .map((res) => {
        return res.json()
    })
    .toPromise();
}

但是控制台显示日志在’FIRST’之前是’最后’.

谢谢.

解决方法

您将不得不创建自己的实现Connection和ConnectionBackend类,并在引导您的应用程序时注入它.请参阅下面的示例代码

export class XHRSynchronousConnection implements Connection    
 {

 }

export class XHRSynchronousConnectionBackend implements ConnectionBackend
{
}

您可以按如下方式引导它

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

您可以在actual source code中看到其余代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读