I have an Angular 4 login Application. I have written accessing logic in login.cmponent.ts file and accessing my login.service.ts file which in turn again calls an authentication service.
When I call authenticate method from my login component, it returns false. By the time it executes remaining code then authentication service returns true because we know Angular run code in asynchronous way.
This is my code:
Login Component Method:
this.loginService.setLoginData(
new LoginModel( this.userId, this.bankId, this.password )
).checkIfLoginSuccessfull();
Login.service Method:
this.authService
.attemptAuth(credentials);
Authentication Service method:
attemptAuth(credentials): void {
this.restService
.post('/authenticate', credentials)
.subscribe(
data => this.setAuth(data.token),
err => this.destroy());
}
Code is working fine. But I want to get results the moment I finish executing checkIfLoginSuccessfull(). I know I am not doing or calling methods ( Observables correctly ).
Please help. :)