Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

background-fetching-indicators.md

58 lines1.1 KB

@Component({
  selector: 'posts',
  template: `
    @switch (query.status()) {
      @case ('pending') {
        Loading...
      }
      @case ('error') {
        An error has occurred: {{ query.error()?.message }}
      }
      @default {
        @if (query.isFetching()) {
          Refreshing...
        }
        @for (todo of query.data()) {
          <todo [todo]="todo" />
        }
      }
    }
  `,
})
export class TodosComponent {
  todosQuery = injectQuery(() => ({
    queryKey: ['todos'],
    queryFn: fetchTodos,
  }))
}
import { injectIsFetching } from '@tanstack/angular-query-experimental'

@Component({
  selector: 'global-loading-indicator',
  template: `
    @if (isFetching()) {
      <div>Queries are fetching in the background...</div>
    }
  `,
})
export class GlobalLoadingIndicatorComponent {
  isFetching = injectIsFetching()
}