I do not understand why Angular Tutorial does not update the heroes list inside .subscribe().
Here is the quote from the tutorial:
Although the component delegates hero deletion to the
HeroService, it remains responsible for updating its own list of heroes. The component'sdelete()method immediately removes the hero-to-delete from that list, anticipating that theHeroServicewill succeed on the server. There's really nothing for the component to do with the Observable returned byheroService.delete()but it mustsubscribeanyway.
Should it be better to do the heroes list update inside the .subscribe() because at that time we are sure that the server successfully delete the hero?
I think making assumption that "the HeroService will succeed on the server" is not good because it is possible that we update our local heroes list, and the server's deletion is not successful.
delete(hero: Hero): void {
this.heroes = this.heroes.filter(h => h !== hero);
this.heroService.deleteHero(hero).subscribe();
}