I am new to RxJS and I am trying to subscribe to an observable function in two different and I am wondering if there is a way to trigger a call from one of the functions can also change the outcome in the second file.
I have an action creator and authGuard subscribe to my loginService and I am trying the action creator will trigger once I call the login function from the auth guard.
action.js
this.loginService.handleLogin(userId)
.subscribe((data) => {
console.log("response in action.js", response);
},
(e) => {
console.log(e);
});
authGuard.js
this.loginService.handleLogin(userId)
.subscribe((response) => {
console.log("response in authGuard.js", response);
}, (err) => {
console.log("error", err);
})
loginService.js
handleLogin(userId) {
const url = `api/user/${userId}`;
return this.http.get(url, { headers: this.headers })
.map((response: Response) => {
return response.json();
})
.catch((e) => {
return Observable.throw(e);
});
}
expectation:
I am expecting to get console.logs results in action.js and authGuard.js when I call handlLogin function of loginService from either file.