【问题标题】:Using ngx-spinner in a http subscribe operation in Angular在 Angular 的 http 订阅操作中使用 ngx-spinner
【发布时间】:2019-07-19 02:28:15
【问题描述】:

我想在 Angular 应用程序中使用微调器。我找到了一个叫做 ngx-spinner 的。然而,没有足够的例子来说明它的实际使用。我想在我的 http 请求中使用它。如何正确显示隐藏/显示微调器?

public getCars(){
 this.spinner.show();
  this.appService.getCars().subscribe(
    car => {
      this.carList=car;
      for (let i = 0; i < this.carList.length; i++) {
        let make = this.carList[i].make;
      }
    },
  );
 this.spinner.hide();

}

我安装了 ngx-spinner 并正确导入。该库正在运行,但我无法在我的 http 请求中正确使用它。 欢迎任何帮助。

【问题讨论】:

    标签: angular typescript http promise spinner


    【解决方案1】:

    我认为你必须移动“this.spinner.hide();”直接在“for”语句的右大括号下。这是成功回调。

    【讨论】:

      【解决方案2】:

      试试这个:

      public getCars(){
           this.spinner.show();
            this.appService.getCars().subscribe(
              car => {
                this.carList=car;
                for (let i = 0; i < this.carList.length; i++) {
                  let make = this.carList[i].make;
                }
                this.spinner.hide();
              },
            );
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-02-22
        • 1970-01-01
        • 2021-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-27
        • 2023-02-12
        相关资源
        最近更新 更多