0
I have a loading that is activated at the beginning of my request and I need to stop it at the end of the request.
I tried something like:
onSubmit() {
this.submitted = true;
if (this.loginForm.invalid) {
return;
}
this.loading = true;
this.authenticationService.login(this.f.username.value, this.f.password.value)
.pipe(first())
.subscribe(data => {
this.router.navigate([this.returnUrl]);
},
error => {throw error},
() => {this.loading = false}
)
}
The loading is not stopping. I remember I had a third subscribe parameter that occurs when the request ends, but I’m not able to implement it.
If you add a
console.log
in this third function, it will be executed?– Woss
complete parameter
– Leonardo Getulio
@Andersoncarloswoss does not perform...
– veroneseComS
Depending on where your source comes from subscribe doesn’t die, it keeps perpetuating expecting new updates. Example: in a request via API it returns the data in the
next
and then dies then sending acomplete
, If you sign an internal status change from your application and don’t fire a complete one by it, your subscribe will always be listening anext
, in this case you could terminate theloading
within thenext
.– Leonardo Getulio
I got it with a rxjs operator, I put the answer if anyone needs it
– veroneseComS
In your case, as the
next
is omitted, it is being processed when you receive your objectdata
, just clearing up.– Leonardo Getulio
@Leonardo thanks for the clarifications
– veroneseComS