Hello there! I am new to learning angular
and typescript
, and currently going through a tutorial at angular. However, I stumbled upon something that I find confusing. For example:
1.
getHeroes(): Observable<Hero[]> {
this.messageService.add('HeroService: fetched heroes');
console.log(this.http);
return this.http.get<Hero[]>(this.heroesUrl);
}
In the above code snippet, I am puzzled about the significance of <Hero[]>
in Observable<Hero[]>
and
this.http.get<Hero[]>(this.heroesUrl)
.
2.
getHero(id: number): Observable<Hero> {
this.messageService.add(`HeroService: fetched hero id=${id}`);
return of(HEROES.find(hero => hero.id === id));
}
If you notice closely in
HeroService: fetched hero id=${id}
, it is enclosed with backticks (`) instead of single quotes ('). Why is that? Also, regarding HEROES.find(hero => hero.id === id)
, what exactly does =>
signify?
I must admit, I am quite new to all of this, so please forgive me if my queries come across as offensive or triggering. Thank you for your patience!
Best regards,