1 import { Component, OnInit } from '@angular/core';
2 import { Hero } from '../hero';
3 import { HeroService } from '../hero.service';
4 import { MessageService } from '../message.service';
7 selector: 'app-heroes',
8 templateUrl: './heroes.component.html',
9 styleUrls: ['./heroes.component.css']
11 export class HeroesComponent implements OnInit {
16 private heroService : HeroService,
17 private messageService : MessageService) { }
26 .subscribe(heroes => this.heroes = heroes);
29 add(name: string): void {
31 if (!name) { return; }
32 this.heroService.addHero({ name } as Hero)
34 this.heroes.push(hero);