【发布时间】:2021-05-19 00:43:21
【问题描述】:
我找不到 SO 的解决方案。
如何调试和检查下面的hello?
getHero(): void {
const id = parseInt(this.route.snapshot.paramMap.get('id') !, 10);
this.heroService.getHero(id)
.subscribe(hero => this.hero = hero);
}
https://stackblitz.com/angular/roynrxqmenv?file=src%2Fapp%2Fhero-detail%2Fhero-detail.component.ts
有什么想法吗?
同理,下面如何调试getHero的返回值。
下面的h 不显示任何内容。
getHero(id: number): Observable<Hero> {
const url = `${this.heroesUrl}/${id}`;
return this.http.get<Hero>(url).pipe(
tap(h => this.log(`fetched hero id=${id}`)),
catchError(this.handleError<Hero>(`getHero id=${id}`))
);
}
https://stackblitz.com/angular/roynrxqmenv?file=src%2Fapp%2Fhero.service.ts
【问题讨论】:
标签: angular typescript