From 81837bdc608e3a0983abf5bd141250324fdf7121 Mon Sep 17 00:00:00 2001 From: "DESKTOP-P9VU163\\admin" Date: Thu, 19 Jun 2025 09:31:36 +0300 Subject: [PATCH] add Update HeroesComponent --- src/app/hero.service.ts | 8 +++++++- src/app/heroes/heroes.component.ts | 13 +++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app/hero.service.ts b/src/app/hero.service.ts index 2220a68..b0e19a1 100644 --- a/src/app/hero.service.ts +++ b/src/app/hero.service.ts @@ -1,9 +1,15 @@ import { Injectable } from '@angular/core'; +import { Hero } from './hero'; +import { HEROES } from './mock-heroes'; @Injectable({ providedIn: 'root' }) export class HeroService { + getHeroes(): Hero[] { + return HEROES; +} constructor() { } -} \ No newline at end of file +} + diff --git a/src/app/heroes/heroes.component.ts b/src/app/heroes/heroes.component.ts index e1ab675..a3b3997 100644 --- a/src/app/heroes/heroes.component.ts +++ b/src/app/heroes/heroes.component.ts @@ -2,7 +2,7 @@ import { Component } from '@angular/core'; import { Hero } from '../hero'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; -import {HEROES} from '../mock-heroes'; +import { HeroService } from '../hero.service'; //новая библиотека добавлена вместо HEROES import { HeroDetailComponent } from '../hero-detail/hero-detail.component'; @Component({ @@ -13,13 +13,22 @@ import { HeroDetailComponent } from '../hero-detail/hero-detail.component'; }) export class HeroesComponent { //определяем класс со списком героев - heroes = HEROES; + heroes: Hero[] = []; selectedHero?: Hero; onSelect(hero: Hero): void { this.selectedHero = hero; } + getHeroes(): void { + this.heroes = this.heroService.getHeroes(); + } + + ngOnInit(): void { + this.getHeroes(); +} + constructor(private heroService: HeroService) {} + }