I am novice in Angular2. Can someone please help me in below problem. I want to call 'update_settings' API after getting response of Login as login response/information is use in second API. What happen is I can't able to call the second API. It simply returns from login function without any output. Login API works fine but second not. In Angular 1 we use chaining but here I tried many things but nothing works. Can someone please help me in this regard?
login(username, password): Observable<any> {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this._httpService
.post(
'login_URL',
JSON.stringify( { username: username, pass: password }),
{headers}
)
.map(res => {
if (res) {
this._httpService.post('update_settings_URL', JSON.stringify( { client_id: res.client_id }))
.map(new_res => {
return { token: res.access_token };
})
}
});
}
http.service.ts
post(uri: string, body: string, options?: RequestOptionsArgs): Observable<any> {
return this._http.post(this.endPointFullUrl(uri), body, this.requestOptionsArgs(options))
.map(response => {
try {
return response.json();
} catch (err) {
/*In case if response body is empty, 200 response code also invokes
error handlers as empty 'response.json()' throws exception.
This way an undefined is returned as the response object
which can easily be handled in the success observers down the chain.
*/
}
});
}