Property 'map' does not exist on type 'Observable<Response>'.ts(2339)

2,505 views
Skip to first unread message

William Manley

unread,
Mar 2, 2020, 1:50:33 AM3/2/20
to Angular and AngularJS discussion
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import { User } from './user';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';


@Injectable()
export class UserService{
   
   constructor(private _httpService: Http){}
    getAllUsers(): Observable<User[]>{
       return this._httpService.get("http://localhost:7777/webapp/user")
               .map((response: Response) => response.json())
               .catch(this.handleError);
   }

    private handleError(error: Response){
       return Observable.throw(error);
   }

}

Error: Property 'map' does not exist on type 'Observable<Response>'.ts(2339)

Angular CLI: 9.0.4
Node: 12.16.1
OS: win32 x64

Angular: 9.0.4

Thang Le Duc

unread,
Mar 2, 2020, 2:05:27 AM3/2/20
to Angular and AngularJS discussion
For versions of RxJS 6.x.x and above, you will have to use pipeable operators.
Try this:
 return this._httpService.get("http://localhost:7777/webapp/user")
               .pipe(map((response: Response) => response.json()))
               .catch(this.handleError);
Reply all
Reply to author
Forward
0 new messages