[当我执行HTTP请求(例如GET请求)并且获得了针对无效给定数据的状态代码400时,它阻止了我的HTML模板显示在我的角度应用程序视图中。这就是我目前的处理方式:
this.myService.getData(neededData)
.subscribe(
(result) => {
this.data = result;
},
(error) => {
if (error) {
console.log("error");
this.anErrorHasOccured = true;
}
}
);
“错误”已在控制台中很好地显示,但是此错误使我的模板无法显示,如何解决?
您可以尝试这个吗:
this.myService.getData(neededData)
.pipe(catchError(err => {
console.err(err);
return of([]);
}))
.subscribe(
(result) => this.data = result,
);