1

I am new to angular JS and I am trying to work out the following.

I am taking a CSV file as input from the user and sending it to the controller on clicking a submit button.

<button class="btn btn-primary" type="submit"ng-click="Input(File)">Submit</button>

My controller is as follows

$scope.Input = function(file) 
{
  var t = file.toString().split("\n");
  var head = t[0].split(",");
  console.log(head);
}

I am trying to print the header of the uploaded CSV file. But in the console I am getting ["[object File]"]. Can someone help me on how to modify the code to get the header of uploaded csv file.

Mini
  • 149
  • 1
  • 7

1 Answers1

0

you can install this npm package . https://www.npmjs.com/package/csv-grape

CsvGrape.getCsvData(event).then((_response)=>{
      let header=_response.Headers; //header array
      
    },(reject)=>{
      log
    });
Nihar Sarkar
  • 1,187
  • 1
  • 13
  • 26