parent
02d98ed823
commit
a1d436e6a4
|
@ -20,7 +20,8 @@ export class HeroesComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeroes(): void {
|
getHeroes(): void {
|
||||||
this.heroesService.getHeroes().subscribe(heroes => (this.heroes = heroes));
|
this.heroesService.getHeroes()
|
||||||
|
.subscribe(heroes => (this.heroes = heroes));
|
||||||
}
|
}
|
||||||
|
|
||||||
add(name: string): void {
|
add(name: string): void {
|
||||||
|
@ -42,7 +43,9 @@ export class HeroesComponent implements OnInit {
|
||||||
delete(hero: Hero): void {
|
delete(hero: Hero): void {
|
||||||
this.heroes = this.heroes.filter(h => h !== hero);
|
this.heroes = this.heroes.filter(h => h !== hero);
|
||||||
// #docregion delete-hero-subscribe
|
// #docregion delete-hero-subscribe
|
||||||
this.heroesService.deleteHero(hero.id).subscribe();
|
this.heroesService
|
||||||
|
.deleteHero(hero.id)
|
||||||
|
.subscribe();
|
||||||
// #enddocregion delete-hero-subscribe
|
// #enddocregion delete-hero-subscribe
|
||||||
/*
|
/*
|
||||||
// #docregion delete-hero-no-subscribe
|
// #docregion delete-hero-no-subscribe
|
||||||
|
@ -67,7 +70,9 @@ export class HeroesComponent implements OnInit {
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
if (this.editHero) {
|
if (this.editHero) {
|
||||||
this.heroesService.updateHero(this.editHero).subscribe(hero => {
|
this.heroesService
|
||||||
|
.updateHero(this.editHero)
|
||||||
|
.subscribe(hero => {
|
||||||
// replace the hero in the heroes list with update from server
|
// replace the hero in the heroes list with update from server
|
||||||
const ix = hero ? this.heroes.findIndex(h => h.id === hero.id) : -1;
|
const ix = hero ? this.heroes.findIndex(h => h.id === hero.id) : -1;
|
||||||
if (ix > -1) {
|
if (ix > -1) {
|
||||||
|
|
Loading…
Reference in New Issue