Open web-dave opened 6 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="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
-->
<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
)