I'm having trouble finding a solution on SO.
Can anyone help me debug and check the code snippet below for 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
The code displays undefined
, even though it should have a value,
https://i.sstatic.net/jYqrS.png
Any suggestions on how to tackle this issue?
Likewise, I need help debugging the returned value for getHero
function below.
The variable h
is not showing any data.
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