40 lines
797 B
TypeScript
40 lines
797 B
TypeScript
import { Component } from '@angular/core';
|
|
import { Beer } from './beer';
|
|
import { BeerService } from './beer.service';
|
|
import { OnInit } from '@angular/core';
|
|
|
|
import { Router } from '@angular/router'
|
|
|
|
@Component({
|
|
moduleId: module.id,
|
|
selector: 'my-beer-list',
|
|
templateUrl: './beer-list.component.html'
|
|
})
|
|
|
|
export class BeerListComponent implements OnInit {
|
|
beers: Beer[];
|
|
selectedBeer: Beer;
|
|
|
|
constructor(
|
|
private router: Router,
|
|
private beerService: BeerService) { }
|
|
|
|
getBeers(): void {
|
|
this.beerService
|
|
.getAll()
|
|
.subscribe(b => this.beers = b);
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.getBeers();
|
|
}
|
|
|
|
onSelect(beer: Beer): void {
|
|
this.selectedBeer = beer;
|
|
}
|
|
|
|
gotoDetail(): void {
|
|
this.router.navigate(['/detail', this.selectedBeer.id]);
|
|
}
|
|
}
|