Skip to content

Commit c61ff1e

Browse files
authored
docs(angular-query): add query options from a service example (#8220)
1 parent 1865f0d commit c61ff1e

25 files changed

+477
-16
lines changed

docs/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,10 @@
10531053
{
10541054
"label": "RxJS autocomplete",
10551055
"to": "framework/angular/examples/rxjs"
1056+
},
1057+
{
1058+
"label": "Query options from a service",
1059+
"to": "framework/angular/examples/query-options-from-a-service"
10561060
}
10571061
]
10581062
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "Node.js",
3+
"image": "mcr.microsoft.com/devcontainers/javascript-node:18"
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @ts-check
2+
3+
/** @type {import('eslint').Linter.Config} */
4+
const config = {}
5+
6+
module.exports = config
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# TanStack Query Angular query options from a service example
2+
3+
To run this example:
4+
5+
- `npm install` or `yarn` or `pnpm i` or `bun i`
6+
- `npm run start` or `yarn start` or `pnpm start` or `bun start`
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"cli": {
5+
"packageManager": "pnpm",
6+
"analytics": false,
7+
"cache": {
8+
"enabled": false
9+
}
10+
},
11+
"newProjectRoot": "projects",
12+
"projects": {
13+
"query-options-from-a-service": {
14+
"projectType": "application",
15+
"schematics": {
16+
"@schematics/angular:component": {
17+
"inlineTemplate": true,
18+
"inlineStyle": true,
19+
"skipTests": true
20+
},
21+
"@schematics/angular:class": {
22+
"skipTests": true
23+
},
24+
"@schematics/angular:directive": {
25+
"skipTests": true
26+
},
27+
"@schematics/angular:guard": {
28+
"skipTests": true
29+
},
30+
"@schematics/angular:interceptor": {
31+
"skipTests": true
32+
},
33+
"@schematics/angular:pipe": {
34+
"skipTests": true
35+
},
36+
"@schematics/angular:resolver": {
37+
"skipTests": true
38+
},
39+
"@schematics/angular:service": {
40+
"skipTests": true
41+
}
42+
},
43+
"root": "",
44+
"sourceRoot": "src",
45+
"prefix": "app",
46+
"architect": {
47+
"build": {
48+
"builder": "@angular-devkit/build-angular:application",
49+
"options": {
50+
"outputPath": "dist/query-options-from-a-service",
51+
"index": "src/index.html",
52+
"browser": "src/main.ts",
53+
"polyfills": ["zone.js"],
54+
"tsConfig": "tsconfig.app.json",
55+
"assets": ["src/favicon.ico", "src/assets"],
56+
"styles": [],
57+
"scripts": []
58+
},
59+
"configurations": {
60+
"production": {
61+
"budgets": [
62+
{
63+
"type": "initial",
64+
"maximumWarning": "500kb",
65+
"maximumError": "1mb"
66+
},
67+
{
68+
"type": "anyComponentStyle",
69+
"maximumWarning": "2kb",
70+
"maximumError": "4kb"
71+
}
72+
],
73+
"outputHashing": "all"
74+
},
75+
"development": {
76+
"optimization": false,
77+
"extractLicenses": false,
78+
"sourceMap": true
79+
}
80+
},
81+
"defaultConfiguration": "production"
82+
},
83+
"serve": {
84+
"builder": "@angular-devkit/build-angular:dev-server",
85+
"configurations": {
86+
"production": {
87+
"buildTarget": "query-options-from-a-service:build:production"
88+
},
89+
"development": {
90+
"buildTarget": "query-options-from-a-service:build:development"
91+
}
92+
},
93+
"defaultConfiguration": "development"
94+
},
95+
"extract-i18n": {
96+
"builder": "@angular-devkit/build-angular:extract-i18n",
97+
"options": {
98+
"buildTarget": "query-options-from-a-service:build"
99+
}
100+
}
101+
}
102+
}
103+
}
104+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@tanstack/query-example-angular-query-options-from-a-service",
3+
"type": "module",
4+
"scripts": {
5+
"ng": "ng",
6+
"start": "ng serve",
7+
"build": "ng build",
8+
"watch": "ng build --watch --configuration development"
9+
},
10+
"private": true,
11+
"dependencies": {
12+
"@angular/common": "^17.3.12",
13+
"@angular/compiler": "^17.3.12",
14+
"@angular/core": "^17.3.12",
15+
"@angular/platform-browser": "^17.3.12",
16+
"@angular/platform-browser-dynamic": "^17.3.12",
17+
"@angular/router": "^17.3.12",
18+
"@tanstack/angular-query-experimental": "^5.59.16",
19+
"rxjs": "^7.8.1",
20+
"tslib": "^2.6.3",
21+
"zone.js": "^0.14.8"
22+
},
23+
"devDependencies": {
24+
"@angular-devkit/build-angular": "^17.3.8",
25+
"@angular/cli": "^17.3.8",
26+
"@angular/compiler-cli": "^17.3.12",
27+
"@tanstack/angular-query-devtools-experimental": "^5.59.16",
28+
"typescript": "5.3.3"
29+
}
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<p>
2+
As you visit the posts below, you will notice them in a loading state the
3+
first time you load them. However, after you return to this list and click on
4+
any posts you have already visited again, you will see them load instantly and
5+
background refresh right before your eyes!
6+
<strong>
7+
(You may need to throttle your network speed to simulate longer loading
8+
sequences)
9+
</strong>
10+
</p>
11+
<angular-query-devtools initialIsOpen />
12+
<router-outlet />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component } from '@angular/core'
2+
import { RouterOutlet } from '@angular/router'
3+
import { AngularQueryDevtools } from '@tanstack/angular-query-devtools-experimental'
4+
5+
@Component({
6+
selector: 'app-root',
7+
standalone: true,
8+
imports: [AngularQueryDevtools, RouterOutlet],
9+
templateUrl: './app.component.html',
10+
styles: [],
11+
})
12+
export class AppComponent {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { provideHttpClient, withFetch } from '@angular/common/http'
2+
import { provideRouter, withComponentInputBinding } from '@angular/router'
3+
import {
4+
QueryClient,
5+
provideAngularQuery,
6+
} from '@tanstack/angular-query-experimental'
7+
8+
import { routes } from './app.routes'
9+
import type { ApplicationConfig } from '@angular/core'
10+
11+
export const appConfig: ApplicationConfig = {
12+
providers: [
13+
provideAngularQuery(new QueryClient()),
14+
provideHttpClient(withFetch()),
15+
provideRouter(routes, withComponentInputBinding()),
16+
],
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Route } from '@angular/router'
2+
3+
// loadComponent lazily loads the component
4+
// when the component is the default export, there is no need to handle the promise
5+
6+
export const routes: Array<Route> = [
7+
{
8+
path: '',
9+
loadComponent: () => import('./components/posts.component'),
10+
},
11+
{
12+
path: 'post/:postId',
13+
loadComponent: () => import('./components/post.component'),
14+
},
15+
]

0 commit comments

Comments
 (0)