So I have looked into all the different things about how "all you have to do is add .subscribe()" and that is not doing anything, so here is what I have:
private loginPost(username: string, password: string): Observable<LoginResponse> {
return this.http.post<LoginResponse>(
'/api/login',
new Login(
username,
password))
.pipe(catchError(this.handleError));
}
Then in a form submit handler I have this:
this.loginPost(
this.f.username.value,
this.f.password.value)
.subscribe(
(response: LoginResponse) => {
console.log(1);
if (response && response.Token && response.Succeeded) {
this.authorizeService.setUser(response);
this.navigateToReturnUrl(this.getReturnUrl());
} else if (!response.Succeeded && response.NeedsPasswordReset) {
this.navigateToReturnUrl(this.getReturnUrl());
this.Loading = false;
} else {
this.Message = 'Username or password is incorrect';
this.Loading = false;
}
});
The result is this (in chrome):
As well as this in the console:
The backend api call is never triggered, and no network call is ever done.
Things I have tried (none made any difference):
- Enabling CORS
- Converting the subscribe to a promise
- While using a promise using
await
andasync
is all different combos - Setting the result of
loginPost
to a const and calling .subscribe() in different ways (with and without handler functions) - Trying different combos of pipe handlers
Edit: In response to the comments: No network call is getting made, no errors are made, subscribe is called and no logs are generated. Per the question, no call is made, the backend is never triggered and the subscribe is not invoked. Googling "angular http subscribe never triggers" you can find I am not the only one seeing this issue. Most of these issues are unanswered and the response is the same across almost all of them. This seems to be a common issue that even with a subscribe angular doesn't make calls, I have even attempted gets and other calls with no luck. If anyone knows how to add more extensive logging that would be really helpful as no error handlers get invoked either so it just stops and doesn't do anything.