Angular 单击角4中的“取消”时,移除中的加载程序

Angular 单击角4中的“取消”时,移除中的加载程序,angular,loader,angular-services,angular-forms,angular-observable,Angular,Loader,Angular Services,Angular Forms,Angular Observable,我有一个名为ngx加载的npm包。我必须将this.loading=true和this.loading=false设置为显示和不显示。当我在javascript中使用警报时,问题就出现了。警报显示“确定”和“取消”。单击“确定”时,加载程序将消失,而单击“取消”和“x”时,加载程序仍会出现?单击“取消”或“x”按钮时,如何使加载程序消失?下面是我所做的 TS 请尝试以下方法: onUpdate(form: NgForm) { this.loading = true; name = f

我有一个名为ngx加载的npm包。我必须将this.loading=true和this.loading=false设置为显示和不显示。当我在javascript中使用警报时,问题就出现了。警报显示“确定”和“取消”。单击“确定”时,加载程序将消失,而单击“取消”和“x”时,加载程序仍会出现?单击“取消”或“x”按钮时,如何使加载程序消失?下面是我所做的

TS

请尝试以下方法:

onUpdate(form: NgForm) {
  this.loading = true;

  name =  form.value.name,
var _confirm = confirm('Are you sure you want to update?');
  if (_confirm ) {
    this.subscription = this.prodService.update(name)
    .subscribe(
      data => {
       this.loading = false;
       console.log(data); 
     },
     error => {
       this.loading = false;
       console.log(error);
     });
  }
else {
 this.loading = false;
}
}
请尝试以下方法:

onUpdate(form: NgForm) {
  this.loading = true;

  name =  form.value.name,
var _confirm = confirm('Are you sure you want to update?');
  if (_confirm ) {
    this.subscription = this.prodService.update(name)
    .subscribe(
      data => {
       this.loading = false;
       console.log(data); 
     },
     error => {
       this.loading = false;
       console.log(error);
     });
  }
else {
 this.loading = false;
}
}

当用户单击取消时,只需添加一个else条件

onUpdate(form: NgForm) {
  this.loading = true;

  name =  form.value.name,

  if (confirm('Are you sure you want to update?')) {
    this.subscription = this.prodService.update(name)
    .subscribe(
      data => {
       this.loading = false;
       console.log(data); 
     },
     error => {
       this.loading = false;
       console.log(error);
     });
  } else {
    this.loading = false;
  }
}

当用户单击取消时,只需添加一个else条件

onUpdate(form: NgForm) {
  this.loading = true;

  name =  form.value.name,

  if (confirm('Are you sure you want to update?')) {
    this.subscription = this.prodService.update(name)
    .subscribe(
      data => {
       this.loading = false;
       console.log(data); 
     },
     error => {
       this.loading = false;
       console.log(error);
     });
  } else {
    this.loading = false;
  }
}