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

posts.service.ts

50 lines1.3 KB

1import { Injectable } from '@angular/core'
2import { of, tap } from 'rxjs'
3import { delay } from 'rxjs/operators'
4​
5@Injectable({
6 providedIn: 'root',
7})
8export class PostsService {
9 allPosts$ = () =>
10 of(posts).pipe(tap(() => console.log('fetching posts')), delay(50))
12​
13export interface Post {
14 id: number
15 title: string
16 body: string
18​
19const posts: Array<Post> = [
20 {
21 id: 1,
22 title: 'Render on the server',
23 body: 'The initial HTML is produced by Angular SSR before the browser bootstraps the app.',
24 },
25 {
26 id: 2,
27 title: 'Hydrate on the client',
28 body: 'Angular reuses the rendered DOM and turns it into a live client application.',
29 },
30 {
31 id: 3,
32 title: 'Query on both sides',
33 body: 'TanStack Query resolves during server rendering here, then the browser starts with a fresh client cache.',
34 },
35 {
36 id: 4,
37 title: 'No API needed',
38 body: 'This example uses a deterministic in-memory data source so the SSR example works without external network access.',
39 },
40 {
41 id: 5,
42 title: 'Keep the setup small',
43 body: 'Only the Angular CLI SSR pieces remain: main.server.ts, server.ts and the server application config.',
44 },
45 {
46 id: 6,
47 title: 'Match the other examples',
48 body: 'The rest of the app keeps the same lightweight structure as the existing Angular examples in this repo.',
49 },