Files
bookstore-angular/admin-portal/src/app/components/view-book/view-book.component.ts
Le Deng d06b719984 latest
2017-03-06 08:58:29 -05:00

37 lines
978 B
TypeScript

import { Component, OnInit } from '@angular/core';
import {Params, ActivatedRoute, Router} from "@angular/router";
import {GetBookService} from "../../services/get-book.service";
import {Book} from "../../models/book";
@Component({
selector: 'app-view-book',
templateUrl: './view-book.component.html',
styleUrls: ['./view-book.component.css']
})
export class ViewBookComponent implements OnInit {
private book: Book = new Book();
private bookId: number;
constructor ( private getBookService: GetBookService, private route: ActivatedRoute, private router:Router){
this.route.params.forEach((params: Params) => {
this.bookId = Number.parseInt(params['id']);
});
this.getBookService.getBook(this.bookId).subscribe(
res => {
this.book=res.json();
},
error => console.log(error)
);
}
onSelect(book: Book) {
this.router.navigate(['/editBook', this.book.id]).then(s =>location.reload());
}
ngOnInit(){}
}