Angular 5 - Ng-x spinner not showing when used in function

霸气de小男生 提交于 2019-12-11 02:26:36

问题


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.


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

}


来源:https://stackoverflow.com/questions/52531840/angular-5-ng-x-spinner-not-showing-when-used-in-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!