From 7f6909208e3aab957f9b528a2688daf856b36c5a Mon Sep 17 00:00:00 2001 From: "DESKTOP-P9VU163\\admin" Date: Thu, 19 Jun 2025 10:03:28 +0300 Subject: [PATCH] add Subscribe in HeroesComponent --- src/app/hero.service.ts | 10 +++++++--- src/app/heroes/heroes.component.ts | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app/hero.service.ts b/src/app/hero.service.ts index b0e19a1..588db16 100644 --- a/src/app/hero.service.ts +++ b/src/app/hero.service.ts @@ -1,15 +1,19 @@ import { Injectable } from '@angular/core'; import { Hero } from './hero'; import { HEROES } from './mock-heroes'; +import { Observable, of } from 'rxjs'; @Injectable({ providedIn: 'root' }) + export class HeroService { - getHeroes(): Hero[] { - return HEROES; -} + getHeroes(): Observable { + const heroes = of(HEROES); + return heroes; + } + constructor() { } } diff --git a/src/app/heroes/heroes.component.ts b/src/app/heroes/heroes.component.ts index a3b3997..9743921 100644 --- a/src/app/heroes/heroes.component.ts +++ b/src/app/heroes/heroes.component.ts @@ -21,12 +21,13 @@ export class HeroesComponent { //определяем класс со списк } getHeroes(): void { - this.heroes = this.heroService.getHeroes(); + this.heroService.getHeroes() + .subscribe(heroes => this.heroes = heroes); } ngOnInit(): void { this.getHeroes(); -} + } constructor(private heroService: HeroService) {} }