在 Angular 的 http 订阅操作中使用 ngx-spinner
Using ngx-spinner in a http subscribe operation in Angular
我想在 Angular 应用程序中使用微调器。我找到了一个叫做 ngx-spinner 的工具。然而,没有足够的例子说明它的实际使用。我想在我的 http 请求中使用它。如何正确显示 hide/show 微调器?
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 请求中正确使用它。
欢迎任何帮助。
我认为您必须将 "this.spinner.hide();" 直接移动到 "for" 语句的右括号下方。这是成功回调。
试试这个:
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();
},
);
}
我想在 Angular 应用程序中使用微调器。我找到了一个叫做 ngx-spinner 的工具。然而,没有足够的例子说明它的实际使用。我想在我的 http 请求中使用它。如何正确显示 hide/show 微调器?
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 请求中正确使用它。 欢迎任何帮助。
我认为您必须将 "this.spinner.hide();" 直接移动到 "for" 语句的右括号下方。这是成功回调。
试试这个:
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();
},
);
}