src/app/book-list/grid-view/grid-item/grid-item.component.ts
Component that displays an individual book embedded inside the grid view
selector | book-grid-item |
templateUrl | ./grid-item.component.html |
book
|
Book that this component displays This input property is passed down from the parent GridViewComponent to this component.
Type: |
bookSelected
|
Event emitted by this component when the book's title is clicked A handler can be attached for this event in the parent GridViewComponent. $event type: EventEmitter
|
onClick |
onClick()
|
Emits the
Returns :
void
|
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Book } from "app/models/book.model";
/**
* Component that displays an individual book embedded inside the grid view
*/
@Component({
selector: 'book-grid-item',
templateUrl: './grid-item.component.html'
})
export class GridItemComponent {
/**
* Book that this component displays
*
* This input property is passed down from the parent {@link GridViewComponent}
* to this component.
*/
@Input() book: Book;
/**
* Event emitted by this component when the book's title is clicked
*
* A handler can be attached for this event in the parent {@link GridViewComponent}.
*/
@Output() bookSelected = new EventEmitter<Book>();
/**
* Emits the `bookSelected` event when the book's title is clicked
*/
onClick() {
this.bookSelected.emit(this.book);
}
}
<!-- BOOTSTRAP'S THUMBNAILS, see here: http://getbootstrap.com/components/#thumbnails -->
<div class="thumbnail">
<img src="assets/no-book-cover.png" width="100px" alt="cover">
<div class="caption">
<!-- this button is styled to look like a link -->
<!-- the inline style makes the button text wrap, see here: https://stackoverflow.com/a/18996295 -->
<button type="button" class="btn btn-link" style="white-space: normal"
(click)="onClick()">
<h2 class="h4">{{book.product.title}}</h2>
</button>
<p>{{book.product.description}}</p>
</div>
</div>