title: How can I download file using Angular 5?
body: <p>When I paste <code>my_example_link</code> in a browser the file is automatically downloaded in a proper way. However, when I use source code shown below download doesn't work. I would like to download file after clicking <code>download</code> button. Any ideas what is wrong? I don't get any errors.</p>
  
  <p>user.service.ts:</p>
  
  <pre class="lang-js prettyprint-override"><code>DownloadFiles() {
  
      return this.http.get('my_example_link', {responseType: 'text'});
  
  }
  </code></pre>
  
  <p>uploader.service.ts:</p>
  
  <pre class="lang-js prettyprint-override"><code>DownloadFile(){
  
        this.userService.DownloadFiles()
            .subscribe(
                (data) =&gt; this.downloadFile2(data)), // console.log(data),
                (error) =&gt; console.log("Error downloading the file."),
                () =&gt; console.info("OK");
  }
  
  downloadFile2(data: Response){
    var blob = new Blob([data], { type: 'text/csv' });
    var url= window.URL.createObjectURL(blob);
    window.open(url);
  }
  </code></pre>
  
  <p>something.component.html:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;li class="nav-item" *ngIf="isCloud()"&gt;
      &lt;a  (click)="this.UploaderService.DownloadFile()" download="file23.txt" style='cursor: pointer;' class="nav-link" target="_blank"&gt;
          &lt;i class="nc-icon nc-basket"&gt;&lt;/i&gt; Download
      &lt;/a&gt;
  &lt;/li&gt;
  </code></pre>