Open web-dave opened 7 years ago
ng g c books/book-details
constructor(
private booksService: BooksService,
private router: Router,
private route: ActivatedRoute) { }
selectBook(book: IBook) {
this.router.navigate([book.isbn], {relativeTo: this.route});
}
children: [{
path: '',
component: BookListComponent
}, {
path: ':isbn',
component: BookDetailsComponent
}]
constructor(
private booksService: BooksService,
private router: Router,
private route: ActivatedRoute) { }
ngOnInit() {
this.route
.params
.subscribe((params: {isbn: string}) => {
this.booksService.getBook(params.isbn)
.subscribe(b => {
console.log('!!', b);
this.book = b;
});
});
}
<div class="panel panel-default" *ngIf="book" >
<div class="panel-heading">{{book.title}} ({{book.isbn}})</div>
<div class="panel-body">
<p>{{book.abstract}} <span class="badge">Seitenzahl: {{book.numPages}}</span> </p>
<p>{{book.publisher.name}} ({{book.publisher.url}})</p>
</div>
<div class="panel-footer">{{book.author}}</div>
</div>
book-details
componentbook-preview
should bring you to thisbook-details
component (RoutParams
)