Created
April 5, 2021 07:23
-
-
Save aRmanNM/90aa6d5fb253244d0d6d95183d4ea2ca to your computer and use it in GitHub Desktop.
Observable Data Service
This file contains 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
@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); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment