사용자 도구

사이트 도구


angular:http-observables

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
angular:http-observables [2019/01/15 04:29] – 만듦 taekguangular:http-observables [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1
줄 1: 줄 1:
 ===== HTTP and Observables ===== ===== HTTP and Observables =====
 +
 +==== Observables ====
 +A sequence of items that arrive asynchronously over time.
 +HTTP call - single item
 +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 '@angular/core';
 +import { HttpClient, HttpErrorResponse } from '@angular/common/http';
 +import { IEmployee } from './employee';
 +import { Observable } from 'rxjs';
 +import { catchError, retry } from 'rxjs/operators';
 +
 +// @Injectable({
 +//   providedIn: 'root'
 +// })
 +@Injectable()
 +export class EmployeeService {
 +  private _url: string = "/assets/data/employees.json"
 +
 +  constructor(private http: HttpClient) { }
 +
 +  getEmployees(): Observable<IEmployee[]>{
 +    return this.http.get<IEmployee[]>(this._url)
 +      .pipe(
 +        catchError(this.errorHandler)
 +      );
 +  }
 +  errorHandler(error: HttpErrorResponse){
 +    return Observable.throw(error.message || "Server Error");
 +  }
 +}
 +</file>
  
angular/http-observables.1547526581.txt.gz · 마지막으로 수정됨: 2025/04/15 10:05 (바깥 편집)