2016-09-06 12:43:07 +00:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
2016-09-06 11:44:13 +00:00
|
|
|
|
2016-09-06 11:53:32 +00:00
|
|
|
import { Duck } from "./models";
|
2016-09-06 12:43:07 +00:00
|
|
|
import { DuckService } from "./duck.service";
|
2016-09-06 12:07:33 +00:00
|
|
|
|
2016-09-06 11:44:13 +00:00
|
|
|
@Component({
|
|
|
|
selector: "duckbook-front",
|
2016-09-06 12:43:07 +00:00
|
|
|
templateUrl: "/app/app.component.html",
|
|
|
|
providers: [ DuckService ]
|
2016-09-06 11:44:13 +00:00
|
|
|
})
|
2016-09-06 12:43:07 +00:00
|
|
|
export class AppComponent implements OnInit {
|
|
|
|
ducks = [];
|
2016-09-06 12:07:33 +00:00
|
|
|
selectedDuck: Duck;
|
|
|
|
|
2016-09-06 12:43:07 +00:00
|
|
|
constructor(private duckService: DuckService) {}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.getDucks();
|
|
|
|
}
|
|
|
|
|
|
|
|
getDucks(): void {
|
|
|
|
this.duckService.getDucks().then(ducks => this.ducks = ducks);
|
|
|
|
}
|
|
|
|
|
2016-09-06 12:07:33 +00:00
|
|
|
onSelect(duck: Duck): void {
|
|
|
|
console.log(duck);
|
|
|
|
this.selectedDuck = duck;
|
|
|
|
}
|
|
|
|
|
2016-09-06 11:53:32 +00:00
|
|
|
duck: Duck = {
|
|
|
|
id: 1,
|
|
|
|
color: 'yellow'
|
|
|
|
};
|
|
|
|
}
|