title: How to download Excel file in angular 2
body: <p>I am learning Angular 2 and I am trying to Download the Excel file in angular 2 by fetching customer data from sql server tables using web api.</p>
  
  <p>After searching in google i found some code but using that code i am able  to download  but it does not contain the proper data and file name is also having some guid format</p>
  
  <p>Below is the code i have used:</p>
  
  <p><strong>Component</strong></p>
  
  <pre><code>GetRemindersData()
  {
      var Flag="ALL_SPOTCHECK_RECORDS";
      this.httpService.GetRemindersData(Flag).subscribe(
          data=&gt;this.downloadFile(JSON.stringify(data[1])),
          error =&gt; console.log("Error downloading the file."),
          () =&gt; console.info("OK"));
  }
  
  downloadFile(data:any){
      console.log(data);
      var blob = new Blob([data], { type: 'application/vnd.ms-excel' });
      var url= window.URL.createObjectURL(blob);
      window.open(url);
  }
  </code></pre>
  
  <p><strong>Service.ts</strong></p>
  
  <pre><code>public GetRemindersData(Flag:string){
      var GetRemindersData_URL:string = 'http://localhost:5000/api/RemindersData/?Flag='+Flag;
      return this.http.get(`${GetRemindersData_URL}`)
                  .map((res:Response) =&gt; res.json())
                  .catch((error:any) =&gt; Observable.throw(error.json().error || 'Server error'));
  }
  </code></pre>