我正在学习角度,并观看英雄教程之旅。
在HTTP section中,他们在组件中调用suscribe(),将HTTP操作委托给服务,服务在屏幕上显示日志错误:
HeroService
getHeroes (): Observable<Hero[]> {
return this.http.get<Hero[]>(this.heroesUrl)
.pipe(
tap(heroes => this.log(`fetched heroes`)), // <-- here it is logging
catchError(this.handleError('getHeroes', []))
);
}
}
HeroComponent
getHeroes(): void {
this.heroService.getHeroes()
.subscribe(heroes => this.heroes = heroes);
}
我认为该服务只负责进行HTTP操作,而log / toast应该是组件的责任
任何人都可以告诉我这个吗?