Load books only when needed not in constructor
This commit is contained in:
@@ -91,6 +91,7 @@ export class BookBrowserComponent implements OnInit {
|
||||
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookService.loadBooks();
|
||||
this.sortOptions = SortService.generateSortOptions();
|
||||
const isAllBooksRoute = this.activatedRoute.snapshot.routeConfig?.path === 'all-books';
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ export class BookService {
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
constructor() {
|
||||
this.loadBooks();
|
||||
}
|
||||
|
||||
private loadBooks(): void {
|
||||
loadBooks(): void {
|
||||
const currentState = this.bookStateSubject.value;
|
||||
if (currentState.loaded) {
|
||||
return;
|
||||
}
|
||||
this.http.get<Book[]>(this.url).pipe(
|
||||
tap(books => {
|
||||
this.bookStateSubject.next({
|
||||
|
||||
Reference in New Issue
Block a user