duck-booking-tool-front/app/ducks.component.ts
Gergely Polonkai 8c0ecca40f Move duck list to a service
Signed-off-by: Gergely Polonkai <gergely@polonkai.eu>
2016-09-09 14:41:50 +02:00

36 lines
802 B
TypeScript

import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { Duck } from "./models";
import { DuckService } from "./duck.service";
@Component({
selector: "ducks",
templateUrl: "/app/ducks.component.html",
providers: [ DuckService ]
})
export class DucksComponent implements OnInit {
ducks = [];
selectedDuck: Duck;
constructor(private router: Router,
private duckService: DuckService)
{}
ngOnInit(): void {
this.getDucks();
}
getDucks(): void {
this.duckService.getDucks().then(ducks => this.ducks = ducks);
}
onSelect(duck: Duck): void {
this.selectedDuck = duck;
}
gotoDetail(duck: Duck): void {
this.router.navigate(['/detail', duck.id]);
}
}