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

example-query.component.ts

30 lines922 Bytes

1import { Component, inject } from '@angular/core'
2import { injectQuery } from '@tanstack/angular-query'
3import { ReposQueries } from '../services/repos/queries'
4​
5@Component({
6 selector: 'example-query',
7 template: `
8 <div style="padding-bottom: 20px">
9 @if (query.isPending()) {
10 <div>Loading...</div>
11 }
12 @if (query.isError()) {
13 <div>An error has occurred: {{ query.error().message }}</div>
14 }
15 @if (query.isSuccess()) {
16 @let data = query.data();
17 <h1>{{ data.name }}</h1>
18 <p>{{ data.description }}</p>
19 <strong>πŸ‘€ {{ data.subscribers_count }}</strong>
20 <strong>✨ {{ data.stargazers_count }}</strong>
21 <strong>🍴 {{ data.forks_count }}</strong>
22 }
23 </div>
24 `,
25})
26export class ExampleQueryComponent {
27 readonly #reposQueries = inject(ReposQueries)
28​
29 readonly query = injectQuery(() => this.#reposQueries.detail())