37 lines
874 B
TypeScript
37 lines
874 B
TypeScript
// Keep the Input import for now, we'll remove it later:
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute, Params } from '@angular/router';
|
|
import { Location } from '@angular/common';
|
|
|
|
import { BeerService } from './beer.service';
|
|
import { Beer } from './beer';
|
|
|
|
import 'rxjs/add/operator/switchMap';
|
|
|
|
@Component({
|
|
moduleId: module.id,
|
|
selector: 'my-beer-detail',
|
|
templateUrl: './beer-detail.component.html'
|
|
})
|
|
|
|
export class BeerDetailComponent implements OnInit {
|
|
|
|
constructor(
|
|
private beerService: BeerService,
|
|
private route: ActivatedRoute,
|
|
private location: Location
|
|
) {}
|
|
|
|
beer: Beer;
|
|
|
|
ngOnInit(): void {
|
|
this.route.params
|
|
.switchMap((params: Params) => this.beerService.get(params['id']))
|
|
.subscribe(beer => this.beer = beer);
|
|
}
|
|
|
|
goBack(): void {
|
|
this.location.back();
|
|
}
|
|
}
|