Skip to content

Instantly share code, notes, and snippets.

@e-oz
Created January 25, 2024 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-oz/39c300b9eb350cdc29a4a4f8e3a7b722 to your computer and use it in GitHub Desktop.
Save e-oz/39c300b9eb350cdc29a4a4f8e3a7b722 to your computer and use it in GitHub Desktop.
Example
@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