Skip to content

Instantly share code, notes, and snippets.

@MikeRyanDev
Created August 12, 2016 15:07
Show Gist options
  • Save MikeRyanDev/256802a01012c25311b55f6d168833ce to your computer and use it in GitHub Desktop.
Save MikeRyanDev/256802a01012c25311b55f6d168833ce to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Book } from './models/book';
import { BooksService } from './services/books-service';
@Component({
selector: 'books-app',
template: `
<books-header></books-header>
<book-card
*ngFor="let book of books$ | async"
[book]="book"
[inCollection]="isBookInCollection"
(add)="onAdd()"
(remove)="onRemove()">
</book-card>
`
})
export class BooksAppComponent {
books$: Observable<Book[]>;
isBookInCollection = false;
constructor(service: BooksService) {
this.books$ = service.getBooks();
}
onAdd() {
this.isBookInCollection = true;
}
onRemove() {
this.isBookInCollection = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment