I have a component which a login form: loginForm
which calls my api:
onLogin(): void {
let username = this.loginForm.value.username;
let password = this.loginForm.value.password;
this.api.login(username, password);
.map(res => res.json())
.subscribe(
this._processData,
);
}
There is a service which calls an api: loginService
.
login(username: string, password: string): Subscription<any> {
let headers = new Headers();
headers.append("Content-Type", "application/json");
return this.http.put("https://myapi.com", JSON.stringify({ username: username, password: password}), {
headers: headers
})
.map(res => res.json())
.subscribe(
data => console.log(data),
err => console.log(err),
() => console.log("Done")
);
}
What I want is the error to be handled inside the loginService. But the result back to the onLogin
method.
I tried a variety of mapping handlers (as shown) in the onLogin but could not get it to work. Any thoughts about what I might do wrong?