Skip to content

Commit 84f0084

Browse files
emcdaniel1624KyleAMathewsclaude
authored
feat(angular-db): add Angular injectLiveQuery helper with tests and example app (#424)
Co-authored-by: Kyle Mathews <mathews.kyle@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0962776 commit 84f0084

36 files changed

+5714
-208
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tanstack/angular-db": minor
3+
---
4+
5+
Add @tanstack/angular-db package with Angular integration for TanStack DB

docs/config.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@
5858
"to": "framework/svelte/adapter"
5959
}
6060
]
61+
},
62+
{
63+
"label": "angular",
64+
"children": [
65+
{
66+
"label": "Angular Adapter",
67+
"to": "framework/angular/adapter"
68+
}
69+
]
6170
}
6271
]
6372
},
@@ -198,6 +207,19 @@
198207
"to": "framework/vue/reference/interfaces/uselivequeryreturnwithcollection"
199208
}
200209
]
210+
},
211+
{
212+
"label": "angular",
213+
"children": [
214+
{
215+
"label": "Angular Functions",
216+
"to": "framework/angular/reference/index"
217+
},
218+
{
219+
"label": "injectLiveQuery",
220+
"to": "framework/angular/reference/functions/injectlivequery"
221+
}
222+
]
201223
}
202224
]
203225
}

docs/framework/angular/adapter.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: TanStack DB Angular Adapter
3+
id: adapter
4+
---
5+
6+
## Installation
7+
8+
```sh
9+
npm install @tanstack/angular-db
10+
```
11+
12+
## Angular inject function
13+
14+
See the [Angular Functions Reference](../reference/index.md) to see the full list of functions available in the Angular Adapter.
15+
16+
## Basic Usage

docs/guides/live-queries.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,30 @@ function UserList() {
137137
}
138138
```
139139

140-
For more details on framework integration, see the [React](../../framework/react/adapter) and [Vue](../../framework/vue/adapter) adapter documentation.
140+
In Angular, you can use the `injectLiveQuery` function:
141+
142+
```typescript
143+
import { Component } from '@angular/core'
144+
import { injectLiveQuery } from '@tanstack/angular-db'
145+
146+
@Component({
147+
selector: 'user-list',
148+
template: `
149+
@for (user of activeUsers.data(); track user.id) {
150+
<li>{{ user.name }}</li>
151+
}
152+
`
153+
})
154+
export class UserListComponent {
155+
activeUsers = injectLiveQuery((q) =>
156+
q
157+
.from({ user: usersCollection })
158+
.where(({ user }) => eq(user.active, true))
159+
)
160+
}
161+
```
162+
163+
For more details on framework integration, see the [React](../../framework/react/adapter), [Vue](../../framework/vue/adapter), and [Angular](../../framework/angular/adapter) adapter documentation.
141164

142165
## From Clause
143166

docs/installation.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ npm install @tanstack/vue-db
3333

3434
TanStack DB is compatible with Vue v3.3.0+
3535

36+
## Angular
37+
38+
```sh
39+
npm install @tanstack/angular-db
40+
```
41+
42+
TanStack DB is compatible with Angular v16.0.0+
43+
3644
## Vanilla JS
3745

3846
```sh

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default [
1111
`**/.output/**`,
1212
`**/.nitro/**`,
1313
`**/traildepot/**`,
14+
`examples/angular/**`,
1415
],
1516
},
1617
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Editor configuration, see https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.ts]
12+
quote_type = single
13+
ij_typescript_use_double_quotes = false
14+
15+
[*.md]
16+
max_line_length = off
17+
trim_trailing_whitespace = false

examples/angular/todos/.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
2+
3+
# Compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
/bazel-out
8+
9+
# Node
10+
/node_modules
11+
npm-debug.log
12+
yarn-error.log
13+
14+
# IDEs and editors
15+
.idea/
16+
.project
17+
.classpath
18+
.c9/
19+
*.launch
20+
.settings/
21+
*.sublime-workspace
22+
23+
# Visual Studio Code
24+
.vscode/*
25+
!.vscode/settings.json
26+
!.vscode/tasks.json
27+
!.vscode/launch.json
28+
!.vscode/extensions.json
29+
.history/*
30+
31+
# Miscellaneous
32+
/.angular/cache
33+
.sass-cache/
34+
/connect.lock
35+
/coverage
36+
/libpeerconnection.log
37+
testem.log
38+
/typings
39+
40+
# System files
41+
.DS_Store
42+
Thumbs.db
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": {
3+
"tailwindcss": {},
4+
"autoprefixer": {}
5+
}
6+
}

examples/angular/todos/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Todos
2+
3+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 20.1.6.
4+
5+
## Development server
6+
7+
To start a local development server, run:
8+
9+
```bash
10+
ng serve
11+
```
12+
13+
Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.
14+
15+
## Code scaffolding
16+
17+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
18+
19+
```bash
20+
ng generate component component-name
21+
```
22+
23+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
24+
25+
```bash
26+
ng generate --help
27+
```
28+
29+
## Building
30+
31+
To build the project run:
32+
33+
```bash
34+
ng build
35+
```
36+
37+
This will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed.
38+
39+
## Running unit tests
40+
41+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
42+
43+
```bash
44+
ng test
45+
```
46+
47+
## Running end-to-end tests
48+
49+
For end-to-end (e2e) testing, run:
50+
51+
```bash
52+
ng e2e
53+
```
54+
55+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
56+
57+
## Additional Resources
58+
59+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.

0 commit comments

Comments
 (0)