| 25 | changeDetection: ChangeDetectionStrategy.OnPush, |
| 26 | }) |
| 27 | export class DynamicPageComponent { |
| 28 | private http = inject(HttpClient); |
| 29 | |
| 30 | private postId$ = inject(ActivatedRoute).params.pipe( |
| 31 | map((p) => p['id'] as string), |
| 32 | ); |
| 33 | |
| 34 | post$ = this.postId$.pipe( |
| 35 | switchMap((id) => |
| 36 | this.http.get<{ title: string; body: string }>( |
| 37 | `https://jsonplaceholder.typicode.com/posts/${id}`, |
| 38 | ), |
| 39 | ), |
| 40 | ); |
| 41 | } |