我刚开始学习rxjs和angular2,如何中止一个http请求并返回一个observable,以便在订阅端不会出现错误?当然,如果我只是返回一个对象,我们会得到.searchAlbum(...).subscribe is not a function
的错误。
public searchAlbum (term:string, queryObject?:any) {
if( this.abortSearches){
queryObject.body = null;
return //what to return here? used to be deferred.resolve(queryObject);
}
...
return this.http.request( new Request( options ) )
.map(res => this.extractData(res, queryObject) )
.catch(this.handleError);
}
return Observable.of(queryObject)
。至于请求取消,请参见此链接:https://dev59.com/w1oV5IYBdhLWcg3wPs0Y - Estus Flask