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
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.
Comments