Created
January 21, 2019 22:25
-
-
Save latish/8306fabdf7ec3ec1f1ce2b217e763ceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<app-hero-detail-ui | |
[hero]="hero$ | async" | |
(save)="save($event)" | |
(goBack)="goBack()" | |
></app-hero-detail-ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, Input } from '@angular/core'; | |
import { ActivatedRoute } from '@angular/router'; | |
import { Location } from '@angular/common'; | |
import { Hero } from '../hero'; | |
import { HeroService } from '../hero.service'; | |
import { Observable } from 'rxjs'; | |
@Component({ | |
selector: 'app-hero-detail', | |
templateUrl: './hero-detail.container.component.html', | |
styleUrls: [ ] | |
}) | |
export class HeroDetailContainerComponent { | |
hero$: Observable<Hero>; | |
constructor( | |
private route: ActivatedRoute, | |
private heroService: HeroService, | |
private location: Location | |
) { | |
this.getHero(); | |
} | |
getHero(): void { | |
const id = +this.route.snapshot.paramMap.get('id'); | |
this.hero$ = this.heroService.getHero(id); | |
} | |
goBack(): void { | |
this.location.back(); | |
} | |
save(hero:Hero): void { | |
this.heroService.updateHero(hero) | |
.subscribe(() => this.goBack()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment