Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created May 9, 2020 18:29
Show Gist options
  • Save tkssharma/80a4015a24b8414ff185e3fba89be29e to your computer and use it in GitHub Desktop.
Save tkssharma/80a4015a24b8414ff185e3fba89be29e to your computer and use it in GitHub Desktop.
@Component({
selector: 'app-books',
templateUrl: './books.component.html'
})
export class BooksComponent implements OnDestroy, OnInit {
private ngUnsubscribe = new Subject();
constructor(private booksService: BookService) { }
ngOnInit() {
this.booksService.getBooks()
.pipe(
startWith([]),
filter(books => books.length > 0),
takeUntil(this.ngUnsubscribe)
)
.subscribe(books => console.log(books));
this.booksService.getArchivedBooks()
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(archivedBooks => console.log(archivedBooks));
}
ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment