observable to custom class angular

Solutions on MaxInterview for observable to custom class angular by the best coders in the world

showing results for - "observable to custom class angular"
Oscar
10 Jun 2016
1// Credit: https://codecraft.tv/courses/angular/http/http-with-observables/
2// But I check the code from the answer
3// and on the new angular versions
4// it needed improvment: adding pipe
5
6// FlightStatus is a custom class,
7// it implements an interface of mine
8// which contains 2 parameters as shown here.
9
10// baseApiUrl is the url of my server
11  get_Flight_Status(id: any): Observable<FlightStatus> {
12    return this.http.get(`${baseApiUrl}/${id}`).pipe(map((res: any) => {
13      console.log('res', res);
14      return res.json().results.map((item: { 
15        StatusID: number; StatusName: string; }) => {
16        return new FlightStatus(
17            item.StatusID,
18            item.StatusName,
19        );
20      });
21    }));
22  }