Reputation: 6649
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?
Upvotes: 1
Views: 45
Reputation: 3671
Try importing the map operator in your authservice
import 'rxjs/add/operator/map';
Upvotes: 1