From 88fd95b95db3ee160af3eb441daaf69a6419c2b7 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 2 May 2020 21:26:42 +0200 Subject: [PATCH] 4: Add Services b) Observable data --- src/app/hero.service.ts | 5 +++-- src/app/heroes/heroes.component.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/hero.service.ts b/src/app/hero.service.ts index 7e0771a..a59d76b 100644 --- a/src/app/hero.service.ts +++ b/src/app/hero.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@angular/core'; +import { Observable, of } from 'rxjs'; import { Hero } from './hero'; import { HEROES } from './mock-heroes'; @@ -10,7 +11,7 @@ export class HeroService { constructor() { } - getHeroes() : Hero[] { - return HEROES; + getHeroes() : Observable { + return of(HEROES); } } diff --git a/src/app/heroes/heroes.component.ts b/src/app/heroes/heroes.component.ts index 94f4266..1e29d4e 100644 --- a/src/app/heroes/heroes.component.ts +++ b/src/app/heroes/heroes.component.ts @@ -24,6 +24,8 @@ export class HeroesComponent implements OnInit { } getHeroes() : void { - this.heroes = this.heroService.getHeroes(); + this.heroService + .getHeroes() + .subscribe(heroes => this.heroes = heroes); } } -- 2.20.1