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

simple-example.component.ts

29 lines780 Bytes

1import { ChangeDetectionStrategy, Component, inject } from '@angular/core'
2import { injectQuery } from '@tanstack/angular-query-experimental'
3import { HttpClient } from '@angular/common/http'
4import { lastValueFrom } from 'rxjs'
5​
6interface Response {
7 name: string
8 description: string
9 subscribers_count: number
10 stargazers_count: number
11 forks_count: number
13​
14@Component({
15 changeDetection: ChangeDetectionStrategy.OnPush,
16 selector: 'simple-example',
17 templateUrl: './simple-example.component.html',
18})
19export class SimpleExampleComponent {
20 #http = inject(HttpClient)
21​
22 query = injectQuery(() => ({
23 queryKey: ['repoData'],
24 queryFn: () =>
25 lastValueFrom(
26 this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
27 ),
28 }))