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

simple-example.component.ts

30 lines800 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 standalone: true,
18 templateUrl: './simple-example.component.html',
19})
20export class SimpleExampleComponent {
21 #http = inject(HttpClient)
22​
23 query = injectQuery(() => ({
24 queryKey: ['repoData'],
25 queryFn: () =>
26 lastValueFrom(
27 this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
28 ),
29 }))