Skip to content

Instantly share code, notes, and snippets.

@aRmanNM
Created April 5, 2021 07:23
Show Gist options
  • Save aRmanNM/90aa6d5fb253244d0d6d95183d4ea2ca to your computer and use it in GitHub Desktop.
Save aRmanNM/90aa6d5fb253244d0d6d95183d4ea2ca to your computer and use it in GitHub Desktop.

Revisions

  1. aRmanNM created this gist Apr 5, 2021.
    23 changes: 23 additions & 0 deletions book-store-service.ts
    Original 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);
    });
    }
    }