Reputation: 13
I have a POST request that doesn't seem to execute.
private loginBackend(): Observable<Response> {
const urlSearchParams = new URLSearchParams();
urlSearchParams.append('ticket', this.ticket.toString());
urlSearchParams.append('serviceURL', this.callbackURL);
this.loginEndPoint = (environment.backUri || window.location.origin) + environment.endpoints.login;
console.log("pass")
return this.http
.post(this.loginEndPoint, urlSearchParams, { withCredentials: true })
.map((dt: any) => {
this.isLoggedIn = true;
this.isLogIn();
})
.catch(this.catchResponseError);
}
I'm trying to set a variable to true if the ticket is validated by the backend.
This is the call to the method :
if (this.ticket) {
// We try to autenticate
return this.loginBackend()
}
Upvotes: 1
Views: 53
Reputation: 1047
When using the http client from Angular, you get an observable as a return. This observable has a source. In your case, the source of data is your http call. This source is actually created only when you subscribe to your observable.
So basically, you need to subscribe to your observable to actually make your http post request :
if (this.ticket) {
// We try to authenticate
return this.loginBackend().subscribe(data => {
// Do your stuff with your response
)
}
Hope that helps
Upvotes: 0
Reputation: 222532
You need to use subscribe otherwise it wont get invoked
if (this.ticket) {
// We try to autenticate
return this.loginBackend().subscribe(data=>
}
Upvotes: 4