13
我有这个代码什么是观察到相当于`Promise.reject`
return this.http.get(this.pushUrl)
.toPromise()
.then(response => response.json().data as PushResult[])
.catch(this.handleError);
我想用的observable
代替Promise
我哪有错误返回给调用方法?
什么与Promise.reject
相等?
doSomeGet() {
console.info("sending get request");
this.http.get(this.pushUrl)
.forEach(function (response) { console.info(response.json()); })
.catch(this.handleError);
}
private handleError(error: any) {
console.error('An error occurred', error);
// return Promise.reject(error.message || error);
}
}
调用的方法是:
getHeroes() {
this.pushService
.doSomeGet();
// .then(pushResult => this.pushResult = pushResult)
// .catch(error => this.error = error);
}
上面的代码与''Promise.reject''注释掉工作完全正常。我不知道为什么。你有什么想法吗? – raj