title: Angular 6 - How to download file from URL for both web and mobile version?
body: <p>I'm making a download function which can work on both web and mobile version of my app, using Angular. Here is my current download function:</p>
  
  <pre><code>export(status, id) {
      this.equipmentService.export(status, id).subscribe(data =&gt; {
          const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
          var link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
          link.download = 'Export data equipment.xlsx';
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
      });
  }
  </code></pre>
  
  <p>The function worked perfectly on the web, but it wasn't working on the mobile version. I've tried using the same logic with an already nested <code>&lt;a&gt;</code> tag instead of creating a new one, but it wasn't working either.</p>
  
  <p>Is there any way to perform the download for both web and mobile version?</p>
  
  <p>I'm trying to avoid using third-party libraries and packages, but if that's the only way, then just shoot :) Thanks a lot!</p>
  
  <p>Here is the element which actives the function:</p>
  
  <pre><code>&lt;td mat-cell *matCellDef="let row"&gt;
      &lt;button mat-icon-button [matMenuTriggerFor]="menu" (click)="$event.stopPropagation()"&gt;
          &lt;mat-icon&gt;more_vert&lt;/mat-icon&gt;
      &lt;/button&gt;
      &lt;mat-menu #menu="matMenu" class="mat-menu"&gt;
          &lt;button mat-menu-item (click)="editEquipment(row.Equipment_Id, $event, true)" *ngIf="isEditAvailable"&gt;
              &lt;span&gt;Edit&lt;/span&gt;
          &lt;/button&gt;
          &lt;button mat-menu-item (click)="mark(1 , row.Equipment_Id)"&gt;
              &lt;span&gt;Mark Available&lt;/span&gt;
          &lt;/button&gt;
  
          &lt;!-- Download button --&gt;
          &lt;button mat-menu-item (click)="export(2, row.Equipment_Id)" *ngIf="isViewDetailAvailable"&gt;
              &lt;span&gt;Export&lt;/span&gt;
          &lt;/button&gt;
          &lt;!----&gt;
  
          &lt;button mat-menu-item (click)="deleteEquipment(row.Equipment_Id)" *ngIf="isEditAvailable"&gt;
              &lt;span&gt;Remove&lt;/span&gt;
          &lt;/button&gt;
      &lt;/mat-menu&gt;
  &lt;/td&gt;
  </code></pre>