Created
April 5, 2021 07:23
-
-
Save aRmanNM/90aa6d5fb253244d0d6d95183d4ea2ca to your computer and use it in GitHub Desktop.
Revisions
-
aRmanNM created this gist
Apr 5, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ @Injectable({ providedIn: 'root' }) export class BookStoreService { private _books = new BehaviorSubject<Book[]>([]); public readonly books$: Observable<Book[]> = this._books.asObservable(); constructor(private bookBackend: BookBackendService) { this.getBooks(); } addBook(newBook: Book): void { this.bookBackend.addBook(newBook).subscribe((res) => { this._books.next(res); }); } getBooks(): void { this.bookBackend.getBooks().subscribe((res) => { this._books.next(res); }); } }