How to import map property of rxjs in angular project , Error : Property 'map' does not exist on type 'Observable<Object>'?

Shiva Chandel

I am posing the data on the server in angular with http post request and with rxjs but even after importing map property of rxjs this is giving an error.

import { Injectable } from '@angular/core';
import {HttpClient,HttpHeaders,HttpErrorResponse} from '@angular/common/http';
import {throwError } from 'rxjs';

import 'rxjs/add/operator/map';

@Injectable({
   providedIn: 'root'
})
export class AuthService {


  constructor(private http:HttpClient) { }

  registerUser(user){
    let headers = new HttpHeaders();
    headers.append('content-type','application/json');

    return this.http.post('http://localhost:8080/users/register',user,{headers:headers})
          .map(response =>response.json())
          .catch(this.errorHandler)

  }


  errorHandler(error:HttpErrorResponse){
     return throwError(error.message||"Server not responding");
  }

}

i even import map property like this:

import {map} from 'rxjs/add/operator';

Error:

Property 'map' does not exist on type 'Observable<Object>'

User is a object

SnorreDan

If you are using RXJS 6 or above, the usage of operators has changed a bit.

You import by:

import { map, catchError } from 'rxjs/operators';

You use the map inside of the pipe operator, like:

return this.http.post('http://localhost:8080/users/register',user,{headers:headers})
      .pipe(
          map(response => {
              // doSomething 
          }),
          catchError(error => {
              this.errorHandler(error);
              return of(`Caught an error: ${error}`);
          })
      );

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular 6 - rxjs property 'map' does not exist on type 'observable'

Angular & RXJS - [ts] Property 'map' does not exist on type 'Observable<User>'

Error:Property 'map' does not exist on type 'Observable<Object>

Property 'map' does not exist on type 'Observable' after upgrading rxjs to 6

Angular 5 to 6 Upgrade: Property 'map' does not exist on type Observable

Angular 6: Property 'map' does not exist on type 'Observable<Response>'

Error:Property 'map' does not exist on type 'Observable<User>'

Property 'map' does not exist on type 'Observable<Blob>'

Property 'map' does not exist on type 'Observable<Response>'

property map does not exist on observable response in angular

Property 'map' does not exist on type - Angular Google Maps project

Property 'map' does not exist on type Object

Property 'map' does not exist on type 'Observable<DocumentChangeAction<Event>[]>'

Error: property map doesn't exist on type 'Observable<Response>'

Angular 2 beta.17: Property 'map' does not exist on type 'Observable<Response>'

Angular 6 : where getting error module "rxjs/add/operator/map" and another error 'map' does not exist on type 'Observable<Response>'

Error TS2339: Property 'JSON' does not exist on type 'Object'. ".map(resp => resp.JSON())" angular 4

Angular 5, rxjs map to json, 'json' does not exist on the the type 'object

Property 'catch' does not exist on type 'Observable<IEmployee[]>'.ts(2339) Error is not resolved by adding import 'rxjs/add/operator/catch';

Angular2 map -> subscribe data type error ( Property 'length' does not exist on type 'ErrorObservable'.)

TS2339: Property 'map' does not exist on type 'Object'

Property 'map' does not exist on type 'Object'.ts(2339)

Property 'map' does not exist on type 'Object' - Ionic 3

Property 'filter' does not exist on type '{}' Angular RxJs

Property 'finally' does not exist on type 'Observable<Object>'

Property 'concatMap' does not exist on type 'Observable<Object>'?

Property '' does not exist on type 'Object'. Observable subscribe

Property 'timeout' does not exist on type 'Observable<Object>'

Angular: Property 'then' does not exist on type 'Observable'