我有这个功能:
uploadFiles(files: FileToUpload[]) {
return Observable.create(async (observable) => {
const aborters: Aborter[] = [];
for (const fileToUpload of files) {
let uploadResponse: UploadResponse;
const aborter = Aborter.none;
aborters.push(aborter);
try {
uploadResponse = await this.upload(file)
} catch (err) {
}
}
return () => {
console.log('coooo');
this.files$.next([]);
for (const aborter of aborters) {
if (!aborter.aborted) {
aborter.abort();
}
}
};
});
}
然后我就这样订阅:
this.uploadSubscription = this.uploadService.uploadFiles(this.control.value).subscribe(
() => console.log('progress'),
(e) => {
console.log(`errored with ${e}`);
this.uploadSubscription.unsubscribe();
},
() => {
console.log('completed');
this.uploadSubscription.unsubscribe();
}
);
ngOnDestroy
这样地:
ngOnDestroy() {
if (this.uploadSubscription) {
this.uploadSubscription.unsubscribe();
}
}
但是,即使调用了unsubscribe方法,从
Observable.create