请帮我在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'之前是'最后'.
谢谢.