我定义了以下功能:
searchProducts(searchText: string){
return Observable.create(observer => {
return this._http.get(this._global.baseUrl + "/products/search/searchProducts?search=" + searchText)
.map(res => res.json())
.subscribe(data => {
observer.next(data);
observer.complete();
},
err => {
return Observable.throw(err); // this statement is called
});
});
}
这是调用语句:
this.productService.searchProducts(this.searchItem)
.subscribe(products => {
console.log(products);
},
err => {
console.log(err); // this statement is not getting called
});
问题:当从服务器获取产品时,订阅数据回调被调用,但是当得到错误时(比如网络连接超时或网络错误),err 回调没有被调用。
我完全厌倦了尝试或寻找解决方案,有人可以帮忙吗?