1

I would like to separate functions based on what they do

This is the scenario, when making http request i would like to separate the function that attaches the access token and header from the one that makes the http call

in my reset password.htmlform i have

<button (click)="tryresetPassword()">Reset password>

in the reset-password.ts

tryresetPassword(){
  ..fetch form data
 return this._authservice.resetPassword()
        .subscribe(
          ...here handle response
          )
 }

In the authservice

resetPassword(data):Observable<any>{
const body = JSON.stringify(data);  
return this.httpClient.post(this.authurl + '/default/resetpwd', body)
     .map(
       res=>{
          //set acess token
           return true
          }
        )

 }

now in the _httpClient

  post(url, data) {
   let headers = new Headers();
   this.createGeneralHeaders(headers);

   return this.http.post(url+this._accesstoken, data, {
     headers: headers
    });

After running the app am getting an error

  this._httpclient.post(...).map is not a function

NB the http in the httpclient is the angular2 http passed through the constructor

Wher am i going wrong?

Geoff
  • 6,277
  • 23
  • 87
  • 197
  • Possible duplicate of [Angular 2 HTTP GET with TypeScript error http.get(...).map is not a function in \[null\]](https://stackoverflow.com/questions/34515173/angular-2-http-get-with-typescript-error-http-get-map-is-not-a-function-in) – AT82 Aug 06 '17 at 14:58

1 Answers1

1

Try importing the map operator in your authservice

import 'rxjs/add/operator/map';
Andrei Matracaru
  • 3,511
  • 1
  • 25
  • 29