【发布时间】:2017-01-12 19:27:41
【问题描述】:
我的情况是,promise 在 promise 中。但是,当在包含 promise 上调用 .then 时,我得到了我内心承诺的结果。这很棒,但我不明白为什么它会起作用。为什么我可以这样做:
this.dataService.init().then(d => console.log(d));
而不是这个:
this.dataService.init().then(p => p.then(d => console.log(d));
数据服务
init(){
return this.geo.init().then( p => this.get(p.lat, p.lon));
}
get(lat, lon){
let uri = `${this.baseuri}lat=${lat}&lon=${lon}&appid=${this.appid}`
//this returns a promise
return this.http.get(uri).toPromise()
.then(d => d.json() || {});
}
地理位置服务
init(){
return new Promise( this.getGeolocation );
}
【问题讨论】:
标签: javascript angular promise rxjs