When you encounter the following line of code:
getHeroes (): Observable<Hero[]> {}
It will provide you with an Observable
. The <T>
syntax represents Generics. In this case, the Observable is of type Observable<Heroe[]>
, which returns an array of Hero
class instances. This Observable belongs to RxJs.
To access the value, you must subscribe
to the observable
as shown below:
let heroes: Hero[];
this.getHeroes().subscribe(data => heroes = data);
I recommend delving into the concepts of Generics
and also exploring RxJs
for a better understanding.