我希望每个人都做得很好。可以请有人清楚地解释一下在管道和订阅之间选择哪一个,为什么?当涉及到不仅要获取响应,还要初始化其他一些变量或更改布尔变量时。
还可以看看代码。这是正确的做法吗?
public getAlbums(){
this.enableLoader = false;
this.albumHttpService.getAlbums()
.pipe(
map((response) => {
this.enableLoader = false;
if (!response.albums.length) {
this.noDataSet = true;
if (response.albums === null) {
this.list = [];
}
}
else{
this.noDataSet = false;
this.list = response.albums;
}
}),
catchError((error) => {
this.noDataSet = false;
this.data = [];
throw new Error(error);
})
)
.subscribe();
}
Run Code Online (Sandbox Code Playgroud)
提前致谢