Reputation: 21
I am not sure if someone experiences this. Whenever I'm trying to use ngx-spinner in a function its not working. But when I put it inside the subscribed callback, it's working.
Outside the authservice. This is not showing the spinner.
login() {
this._spinner.show(); //spinner call
this._authService.login(this.user).subscribe(
data => {
sessionStorage.setItem("account", JSON.stringify(data[0].data));
sessionStorage.setItem("token", data[0].data.access_token);
setInterval(() => {
this._router.navigate(['home']);
}, 2000);
},
error => {
}
)
this._spinner.hide();
}
Inside authservice. This is working
login() {
this._authService.login(this.user).subscribe(
data => {
this._spinner.show(); //spinner call
sessionStorage.setItem("account", JSON.stringify(data[0].data));
sessionStorage.setItem("token", data[0].data.access_token);
setInterval(() => {
this._router.navigate(['home']);
}, 2000);
},
error => {
}
)
this._spinner.hide();
}
I've imported all the necessary library, but for some reason, it's not working when it is outside of the authservice.
Upvotes: 2
Views: 765
Reputation: 288
login() {
this._spinner.show(); //spinner call
this._authService.login(this.user).subscribe(
data => {
sessionStorage.setItem("account", JSON.stringify(data[0].data));
sessionStorage.setItem("token", data[0].data.access_token);
setInterval(() => {
this._router.navigate(['home']);
}, 2000);
this._spinner.hide();
},
error => {
this._spinner.hide();
}
)
}
Upvotes: 1