projects
/
examples
/
angular-tour-of-heroes
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
WIP: 6: Get Data from a Server k) Search by name
[examples/angular-tour-of-heroes]
/
src
/
app
/
heroes
/
heroes.component.ts
diff --git
a/src/app/heroes/heroes.component.ts
b/src/app/heroes/heroes.component.ts
index
d8ac642
..
38ab888
100644
(file)
--- a/
src/app/heroes/heroes.component.ts
+++ b/
src/app/heroes/heroes.component.ts
@@
-12,13
+12,6
@@
export class HeroesComponent implements OnInit {
heroes: Hero[];
heroes: Hero[];
- selectedHero : Hero;
-
- onSelect(hero : Hero): void {
- this.selectedHero = hero;
- this.messageService.add(`HeroService: Selected hero id=${hero.id}`);
- }
-
constructor(
private heroService : HeroService,
private messageService : MessageService) { }
constructor(
private heroService : HeroService,
private messageService : MessageService) { }
@@
-32,4
+25,13
@@
export class HeroesComponent implements OnInit {
.getHeroes()
.subscribe(heroes => this.heroes = heroes);
}
.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);
+ });
+ }
}
}