2016-09-06 13:35:20 +00:00
|
|
|
import { Component, Input, OnInit } from "@angular/core";
|
|
|
|
import { ActivatedRoute, Params } from "@angular/router";
|
|
|
|
|
|
|
|
import { DuckService } from "./duck.service";
|
2016-09-06 12:21:25 +00:00
|
|
|
|
|
|
|
import { Duck } from "./models";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "duck-detail",
|
|
|
|
templateUrl: "/app/duck-detail.component.html"
|
|
|
|
})
|
2016-09-06 13:35:20 +00:00
|
|
|
export class DuckDetailComponent implements OnInit {
|
|
|
|
constructor(private duckService: DuckService,
|
|
|
|
private route: ActivatedRoute)
|
|
|
|
{}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.route.params.forEach((params: Params) => {
|
|
|
|
let id = +params['id'];
|
|
|
|
this.duckService.getDuck(id)
|
|
|
|
.then(duck => this.duck = duck);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
goBack(): void {
|
|
|
|
window.history.back();
|
|
|
|
}
|
|
|
|
|
2016-09-06 13:54:03 +00:00
|
|
|
save(): void {
|
|
|
|
this.duckService.update(this.duck)
|
|
|
|
.then(this.goBack);
|
|
|
|
}
|
|
|
|
|
2016-09-06 12:21:25 +00:00
|
|
|
@Input()
|
|
|
|
duck: Duck;
|
|
|
|
}
|