35 lines
1005 B
TypeScript
35 lines
1005 B
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { Hero } from '../hero';
|
|
import { CommonModule } from '@angular/common';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { HeroService } from '../hero.service'; //новая библиотека добавлена вместо HEROES
|
|
import { HeroDetailComponent } from '../hero-detail/hero-detail.component';
|
|
import { MessageService } from '../message.service';
|
|
import { RouterLink } from '@angular/router';
|
|
|
|
@Component({
|
|
selector: 'app-heroes',
|
|
templateUrl: './heroes.component.html',
|
|
styleUrls: ['./heroes.component.css'],
|
|
imports: [CommonModule, FormsModule, RouterLink]
|
|
})
|
|
|
|
export class HeroesComponent implements OnInit {
|
|
|
|
selectedHero?: Hero;
|
|
|
|
heroes: Hero[] = [];
|
|
|
|
constructor(private heroService: HeroService, private messageService: MessageService) { }
|
|
|
|
ngOnInit(): void {
|
|
this.getHeroes();
|
|
}
|
|
|
|
|
|
|
|
getHeroes(): void {
|
|
this.heroService.getHeroes()
|
|
.subscribe(heroes => this.heroes = heroes);
|
|
}
|
|
} |