add Subscribe in HeroesComponent

This commit is contained in:
Костя 2025-06-19 10:03:28 +03:00
parent 81837bdc60
commit 7f6909208e
2 changed files with 10 additions and 5 deletions

View File

@ -1,15 +1,19 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Hero } from './hero'; import { Hero } from './hero';
import { HEROES } from './mock-heroes'; import { HEROES } from './mock-heroes';
import { Observable, of } from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class HeroService { export class HeroService {
getHeroes(): Hero[] { getHeroes(): Observable<Hero[]> {
return HEROES; const heroes = of(HEROES);
return heroes;
} }
constructor() { } constructor() { }
} }

View File

@ -21,7 +21,8 @@ export class HeroesComponent { //определяем класс со списк
} }
getHeroes(): void { getHeroes(): void {
this.heroes = this.heroService.getHeroes(); this.heroService.getHeroes()
.subscribe(heroes => this.heroes = heroes);
} }
ngOnInit(): void { ngOnInit(): void {