Open History to see the last commit
1import {
2 ChangeDetectionStrategy,
3 Component,
4 inject,
5 input,
6 numberAttribute,
7} from '@angular/core'
8import { RouterLink } from '@angular/router'
9import { injectQuery } from '@tanstack/angular-query-experimental'
10import { PostsQueries } from '../services/posts/queries'
11β
12@Component({
13 changeDetection: ChangeDetectionStrategy.OnPush,
14 selector: 'post',
15 templateUrl: './post.component.html',
16 imports: [RouterLink],
17})
18export default class PostComponent {
19 readonly #postsQueries = inject(PostsQueries)
20β
21 // The Angular router will automatically bind postId
22 // as `withComponentInputBinding` is added to `provideRouter`.
23 // See https://angular.dev/api/router/withComponentInputBinding
24 readonly postId = input.required({
25 transform: numberAttribute,
26 })
27β
28 readonly postQuery = injectQuery(() =>
29 this.#postsQueries.detail(this.postId()),
30 )
31}