35 lines
902 B
TypeScript
35 lines
902 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { delay, Observable, shareReplay } from 'rxjs';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class UserService {
|
|
constructor(private http: HttpClient) {}
|
|
|
|
getUsers(): Observable<any[]> {
|
|
return this.http.get<any[]>('https://jsonplaceholder.typicode.com/users').pipe(
|
|
delay(1000)
|
|
)
|
|
}
|
|
|
|
getUser(id: number): Observable<any> {
|
|
return this.http.get<any>(`https://jsonplaceholder.typicode.com/users/${id}`).pipe(
|
|
delay(1000)
|
|
)
|
|
}
|
|
|
|
getTodos(userId: number): Observable<any[]> {
|
|
return this.http.get<any[]>(`https://jsonplaceholder.typicode.com/todos?userId=${userId}`).pipe(
|
|
delay(1000)
|
|
)
|
|
}
|
|
|
|
getTodo(id: number): Observable<any> {
|
|
return this.http.get<any>(`https://jsonplaceholder.typicode.com/todos/${id}`).pipe(
|
|
delay(1000)
|
|
)
|
|
}
|
|
}
|