Created
January 25, 2024 05:47
-
-
Save e-oz/39c300b9eb350cdc29a4a4f8e3a7b722 to your computer and use it in GitHub Desktop.
Example
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({}) | |
export class BookComponent { | |
private readonly bookService = inject(BookService); | |
protected readonly $isLoading = signal(false); | |
readonly bookId = input.required<string>(); | |
protected readonly $bookDetails = toSignal( | |
toObservable(this.bookId).pipe( | |
switchMap((id) => { | |
if (!id) { | |
return EMPTY; | |
} | |
this.$isLoading.set(true); | |
return this.bookService.getBookDetails(id).pipe( | |
finalize(() => this.$isLoading.set(false)), | |
catchError((err) => { | |
console?.error(err); | |
return EMPTY; | |
}) | |
); | |
}) | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment