문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| angular:http-observables [2019/01/15 04:31] – taekgu | angular:http-observables [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 5: | 줄 5: | ||
| HTTP call - single item | HTTP call - single item | ||
| Single item - HTTP response | Single item - HTTP response | ||
| + | |||
| + | ==== HTTP, Observables and RxJS ==== | ||
| + | - HTTP Get request from EmpService | ||
| + | - Receive the observable and cast it into an employee array | ||
| + | - Subscribe to the observable from EmpList and EmpDetail | ||
| + | - Assign the employee array to a local variable | ||
| + | |||
| + | RxJS | ||
| + | * Reactive Extensions from Javascript | ||
| + | * External library to work with Obserables | ||
| + | |||
| + | <file javascript employee.service.ts> | ||
| + | import { Injectable } from ' | ||
| + | import { HttpClient, HttpErrorResponse } from ' | ||
| + | import { IEmployee } from ' | ||
| + | import { Observable } from ' | ||
| + | import { catchError, retry } from ' | ||
| + | |||
| + | // @Injectable({ | ||
| + | // | ||
| + | // }) | ||
| + | @Injectable() | ||
| + | export class EmployeeService { | ||
| + | private _url: string = "/ | ||
| + | |||
| + | constructor(private http: HttpClient) { } | ||
| + | |||
| + | getEmployees(): | ||
| + | return this.http.get< | ||
| + | .pipe( | ||
| + | catchError(this.errorHandler) | ||
| + | ); | ||
| + | } | ||
| + | errorHandler(error: | ||
| + | return Observable.throw(error.message || " | ||
| + | } | ||
| + | } | ||
| + | </ | ||