如何在角度7中使用foreach取消多请求服务?

时间:2019-05-28 12:28:10

标签: angular typescript

我想用角度7的foreach取消多个请求服务。

   this.attachmentList.forEach(email => {
   this._attachmentHttpService.getEmailAttachments(email.id).takeUntil(this.unsubscribe).subscribe((data: any) => {
    email.date = this.dateService.getUtcStringDate(new Date(data.date));
    const byteArray = new Uint8Array(atob(data.content).split('').map(char => char.charCodeAt(0)));
    const blob = new Blob([byteArray], {type: 'application/pdf'});
    const url = window.URL.createObjectURL(blob);
    email.pdfSrc = url;
    email.content = url;
    email.attachementMailName = data.attachementMailName;
    email.blob = blob;
    email.subject = data.subject;

  });     
});

我尝试过这种解决方案:但是我没有成功

 serve: Array<any>;
this.attachmentList.forEach(email => {
 const test=  this._attachmentHttpService.getEmailAttachments(email.id).takeUntil(this.unsubscribe).subscribe((data: any) => {
    email.date = this.dateService.getUtcStringDate(new Date(data.date));
    const byteArray = new Uint8Array(atob(data.content).split('').map(char => char.charCodeAt(0)));
    const blob = new Blob([byteArray], {type: 'application/pdf'});
    const url = window.URL.createObjectURL(blob);
    email.pdfSrc = url;
    email.content = url;
    email.attachementMailName = data.attachementMailName;
    email.blob = blob;
    email.subject = data.subject;       
  });
 this.serve.push(test);
});
this.serve.foreach(data=>{data.unsubscribe()});

哪个是最佳解决方案?

0 个答案:

没有答案