+ getHeroes() : void {
+ this.heroService
+ .getHeroes()
+ .subscribe(heroes => this.heroes = heroes);
+ }
+
+ add(name: string): void {
+ name = name.trim();
+ if (!name) { return; }
+ this.heroService.addHero({ name } as Hero)
+ .subscribe(hero => {
+ this.heroes.push(hero);
+ });
+ }