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

simple-example.component.ts

28 lines701 Bytes

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