title: How do I download a file with Angular2 or greater
body: <p>I have a WebApi / MVC app for which I am developing an angular2 client (to replace MVC). I am having some troubles understanding how Angular saves a file.</p>
  
  <p>The request is ok (works fine with MVC, and we can log the data received) but I can't figure out how to save the downloaded data (I am mostly following the same logic as in <a href="https://stackoverflow.com/questions/22447952/angularjs-http-post-convert-binary-to-excel-file-and-download">this post</a>). I am sure it is stupidly simple, but so far I am simply not grasping it.</p>
  
  <p>The code of the component function is below. I've tried different alternatives, the blob way should be the way to go as far as I understood, but there is no function <code>createObjectURL</code> in <code>URL</code>. I can't even find the definition of <code>URL</code> in window, but apparently it exists. If I use the <a href="https://github.com/eligrey/FileSaver.js" rel="noreferrer"><code>FileSaver.js</code> module</a> I get the same error. So I guess this is something that changed recently or is not yet implemented. How can I trigger the file save in A2?</p>
  
  
  
  <pre class="lang-typescript prettyprint-override"><code>downloadfile(type: string){
  
      let thefile = {};
      this.pservice.downloadfile(this.rundata.name, type)
          .subscribe(data =&gt; thefile = new Blob([data], { type: "application/octet-stream" }), //console.log(data),
                      error =&gt; console.log("Error downloading the file."),
                      () =&gt; console.log('Completed file download.'));
  
      let url = window.URL.createObjectURL(thefile);
      window.open(url);
  }
  </code></pre>
  
  <p>For the sake of completeness, the service that fetches the data is below, but the only thing it does is to issue the request and pass on the data without mapping if it succeeds:</p>
  
  <pre class="lang-typescript prettyprint-override"><code>downloadfile(runname: string, type: string){
     return this.authHttp.get( this.files_api + this.title +"/"+ runname + "/?file="+ type)
              .catch(this.logAndPassOn);
  }
  </code></pre>