What is .subscribe in Angular?

I’m going through angular-tour-of-heroes app, and I encountered .subscribe method in routing. Can someone explain what’s going on here?

Link for the app: https://embed.plnkr.co/?show=preview

Inside hero-detail.component.ts file,

ngOnInit(): void {
  this.route.paramMap
    .switchMap((params: ParamMap) => this.heroService.getHero(+params.get('id')))
    .subscribe(hero => this.hero = hero);
}

Leave a Comment