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中看到其余代码. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |