Answers for "observable to custom class angular"

0

observable to custom class angular

// Credit: https://codecraft.tv/courses/angular/http/http-with-observables/
// But I check the code from the answer
// and on the new angular versions
// it needed improvment: adding pipe

// FlightStatus is a custom class,
// it implements an interface of mine
// which contains 2 parameters as shown here.

// baseApiUrl is the url of my server
  get_Flight_Status(id: any): Observable<FlightStatus> {
    return this.http.get(`${baseApiUrl}/${id}`).pipe(map((res: any) => {
      console.log('res', res);
      return res.json().results.map((item: { 
        StatusID: number; StatusName: string; }) => {
        return new FlightStatus(
            item.StatusID,
            item.StatusName,
        );
      });
    }));
  }
Posted by: Guest on July-25-2021

Code answers related to "observable to custom class angular"

Code answers related to "Javascript"

Browse Popular Code Answers by Language