Angular 5 - Ng-x 微调器在函数中使用时不显示 [英] Angular 5 - Ng-x spinner not showing when used in function

查看:21
本文介绍了Angular 5 - Ng-x 微调器在函数中使用时不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定是否有人遇到过这种情况.每当我尝试在函数中使用 ngx-spinner 时,它都不起作用.但是当我把它放在订阅的回调中时,它就起作用了.

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.

在 authservice 之外.这没有显示微调器.

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();
}

我已经导入了所有必要的库,但由于某种原因,它在 authservice 之外时无法正常工作.

I've imported all the necessary library, but for some reason, it's not working when it is outside of the authservice.

推荐答案

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();
    }
  )

}

这篇关于Angular 5 - Ng-x 微调器在函数中使用时不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆