我在提供者中使用此方法:
get() {
var debugOptionUseLocalDB = 0,
prodata = [],
serverAttempts = 0;
return new Promise((resolve, reject) => {
if (this.connectionStatus.f() === 'online') {
return this.getDBfileXHR(this.dbUrl(), serverAttempts)
.then(function (data) { // success
console.log('-normal XHR request succeeded.');
resolve(data);
})
.catch((reason)=> {
...
})
}
else{
...
}
})
}
我从app.component.ts调用它:
this.updateProDB.get()
.then( () => {
let prodata = this.storageService.get('prodata');
this.imagesService.manageStoredImageUrlsNew(prodata);
})
.catch((reason)=> {
console.error('imagesUrl have not been managed, because updateProDb failed with error:' + reason)
});
我确信this.getDBfileXHR()
已解决,因为我看到'正常的XHR请求成功了'。在控制台中。但是,this.updateProDB.get()rejects, and we go to the
。catch()`。
resolve(data);
是解决get()的正确方法吗?
由于