title: ANGULAR 5 : how to export data to csv file
body: <p>I am beginner in angular and I am working on Angular 5, Node v8.11.3.</p>
  
  <p>I want to realize a generic function that takes in parameter data and headers. And as output a csv file.</p>
  
  <p>I create a component called ' FactureComponent ' Then I generate a service
  called ' DataService ' then I create a getFactures function that retrieves a list of my items from a mock and it works very well.</p>
  
  <pre class="lang-ts prettyprint-override"><code>import { Component, OnInit } from '@angular/core';
  import { DataService } from '../data.service';
  import { FACTURES } from '../mock.factures';
  
  @Component({
  selector: 'app-facture',
  templateUrl: './facture.component.html',
  styleUrls: ['./facture.component.scss']
  })
  export class FactureComponent implements OnInit {
  
  factures = [];
  columns  = ["Id","Reference","Quantite","Prix Unitaire"];
  btnText:  String = "Export CSV";
  
  constructor(private _data: DataService) { }
  
  ngOnInit() {
  this.getFactures();
  }
  getFactures(){
  this.factures=this._data.getFactures();
  }
  generateCSV(){
  console.log("generate");
  }
  }
  </code></pre>
  
  <p>you will find below the view</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form&gt;
  &lt;input type="submit" [value]="btnText" (click)="generateCSV()"/&gt;
  &lt;/form&gt;
  
  &lt;table&gt;
   &lt;tr&gt;
     &lt;th *ngFor="let col of columns"&gt;
        {{col}}
     &lt;/th&gt;
   &lt;/tr&gt;
   &lt;tr *ngFor="let facture of factures"&gt;
    &lt;td&gt;{{facture.id}}&lt;/td&gt;     
    &lt;td&gt;{{facture.ref}}&lt;/td&gt;
    &lt;td&gt;{{facture.quantite}}&lt;/td&gt;
    &lt;td&gt;{{facture.prixUnitaire}}&lt;/td&gt;
   &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>So I want to realize a function that converts my data displayed on the view into a csv file.</p>