0

Ich habe dieses npm-Paket namens ngx-loading. Ich muss this.loading = true und this.loading = false setzen, damit es angezeigt wird und nicht angezeigt wird. Das Problem kommt, wenn ich die Warnung in Javascript verwende. Der Alarm zeigt "OK" und "Abbrechen". Wenn ich auf "OK" klicke verschwindet der Loader, während wenn ich auf "Abbrechen" und "x" klicke erscheint er immer noch? Wie kann ich den Loader verschwinden lassen, wenn ich auf die Schaltfläche Abbrechen oder X klicke? Hier ist, was ich unten getan habe.Entfernen Loader in Wenn Abbrechen in Angular 4

TS

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); 
    }); 
    } 
} 

Antwort

1

einfach einen anderen Zustand hinzuzufügen, wenn der Benutzer klickt abzubrechen.

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; 
    } 
} 
+0

DANKE ES ARBEITET – Joseph

1

die folgenden Versuchen:

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; 
} 
} 
+0

DANKE DANISH – Joseph