【问题标题】:Angular 5 - Ng-x spinner not showing when used in functionAngular 5 - Ng-x 微调器在函数中使用时不显示
【发布时间】:2018-09-27 15:46:41
【问题描述】:

我不确定是否有人遇到过这种情况。 每当我尝试在函数中使用 ngx-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();
}

在身份验证服务中。这是有效的

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 之外时无法正常工作。

【问题讨论】:

    标签: angular angular5 spinner


    【解决方案1】:
    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();
        }
      )
    
    }
    

    【讨论】:

      猜你喜欢
      • 2022-08-05
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      • 2022-12-07
      • 1970-01-01
      相关资源
      最近更新 更多