下面是我的Angular 2服务中的一个方法,它返回一个“类别”对象数组的“Observable” .

// Get all categories
GetCategories():Observable<Array<Category>> {       

      return this.http.get('./categories')
                 .map(data => data.json())
                 .catch(this.handleError);;                                        

}

根据我的理解,上述服务方法返回的“Category”对象数组可以通过2种方式从组件代码中获得

风格1

this.appService.GetCategories().subscribe({next: (data) => {
                                                                    this.appService.categories = data;
                                                                    this.categories = this.appService.categories
                                                                },
                                                error: (err) => {
                                                                    this.toaster.error(err);
                                                                }                
     });

风格2

this.categories$ = this.appService.GetCategories(); // returns an Observable<Array<Category>>

并使用“async”管道访问模板中的数据 .

现在我的问题是,在样式1的情况下,我能够在出现错误时显示错误警报,但如果我使用样式2,我将如何显示自定义错误警报 .