小编unk*_*ser的帖子

Angular 中的管道与订阅

我希望每个人都做得很好。可以请有人清楚地解释一下在管道订阅之间选择哪一个,为什么?当涉及到不仅要获取响应,还要初始化其他一些变量或更改布尔变量时。

还可以看看代码。这是正确的做法吗?

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)

提前致谢

pipe subscribe rxjs angular

12
推荐指数
2
解决办法
1万
查看次数

标签 统计

angular ×1

pipe ×1

rxjs ×1

subscribe ×1