--- id: queries title: Queries ref: docs/framework/react/guides/queries.md replace: { 'React': 'Angular', 'react-query': 'angular-query', 'promise': 'promise or observable', 'custom hooks': 'services', 'the `useQuery` hook': '`injectQuery`', '`useQuery`': '`injectQuery`', "TypeScript will also narrow the type of data correctly if you've checked for pending and error before accessing it.": 'TypeScript will only narrow the type when checking boolean signals such as `isPending` and `isError`.', } --- [//]: # 'Example' ```ts import { injectQuery } from '@tanstack/angular-query-experimental' export class TodosComponent { info = injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodoList })) } ``` [//]: # 'Example' [//]: # 'Example2' ```ts result = injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodoList })) ``` [//]: # 'Example2' [//]: # 'Example3' ```angular-ts @Component({ selector: 'todos', standalone: true, template: ` @if (todos.isPending()) { Loading... } @else if (todos.isError()) { Error: {{ todos.error()?.message }} } @else { @for (todo of todos.data(); track todo.id) {
  • {{ todo.title }}
  • } @empty {
  • No todos found
  • } } `, }) export class PostsComponent { todos = injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodoList, })) } ``` [//]: # 'Example3' If booleans aren't your thing, you can always use the `status` state as well: [//]: # 'Example4' ```angular-ts @Component({ selector: 'todos', standalone: true, template: ` @switch (todos.status()) { @case ('pending') { Loading... } @case ('error') { Error: {{ todos.error()?.message }} } @default { } } `, }) class TodosComponent {} ``` [//]: # 'Example4' [//]: # 'Materials' [//]: # 'Materials'