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

post.component.ts

24 lines772 Bytes

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