我能够解决这个问题。我在 Angular Zone 之外完成了 observable。
task.on('progress', (e) => {
if (e.currentBytes) {
// console.log('progress ->', e.currentBytes);
this.ngZone.run(() => {
this.componentService.loadingIndicator.showProgress({ maxValue: e.totalBytes, value: e.currentBytes });
});
}
});
task.on('error', (e) => {
this.ngZone.run(() => {
observer.error(e.error);
observer.complete();
});
});
task.on('complete', (e: any) => {
this.ngZone.run(() => {
observer.next(JSON.parse(e.response.getBodyAsString()));
observer.complete();
});
console.log('complete upload');
});