I've been stumped trying to figure out the inner workings of the mysterious .subscribe
method.
getHeroes(): void {
this.heroService.getHeroes()
.subscribe(heroes => this.heroes = heroes);
}
Initially, I believed that this.heroes = heroes
was assigning values to heroes:Hero[]
within the heroes component. However, it appears that this assumption is incorrect. Surprisingly, even if I alter heroes:Hero[]
to heroes:boolean
, or remove it entirely from the heroes component, my heroes are still displayed and this.heroes
is still assigned.
Could someone shed some light on how this is happening?
Feel free to experiment with the suggested changes, such as deleting heroes:Hero[]
, and observe how the heroes remain visible. If this.heroes = heroes
isn't assigning to heroes:Hero[]
, what exactly is occurring within the subscribe method?