Created
May 9, 2020 18:29
-
-
Save tkssharma/80a4015a24b8414ff185e3fba89be29e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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