Open History to see the last commit
1import { HttpClient } from '@angular/common/http'
2import { Injectable, inject } from '@angular/core'
3β
4@Injectable({
5 providedIn: 'root',
6})
7export class PostsService {
8 readonly #http = inject(HttpClient)
9β
10 postById$ = (postId: number) =>
11 this.#http.get<Post>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
12β
13 allPosts$ = () =>
14 this.#http.get<Array<Post>>('https://jsonplaceholder.typicode.com/posts')
15}
16β
17export interface Post {
18 id: number
19 title: string
20 body: string
21}