Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert csv to array

I am trying to convert csv to array on angular 1.5+ionic on hebrew. I am using ng-csv. What I done till now:

Html:

    <ng-csv-import
  class="import"
  content="csv.content"
  header="csv.header"
  header-visible="csv.headerVisible"
  separator="csv.separator"
  separator-visible="csv.separatorVisible"
  result="csv.result"
  encoding="csv.encoding"
  encoding-visible="csv.encodingVisible"></ng-csv-import>

my controller is :

   .controller('SettingsCtrl', function ($scope,$parse) {
    $scope.csv = {
      content: null,
      header: true,
      headerVisible: true,
      separator: ',',
      separatorVisible: true,
      result: null,
      encoding: 'Windows-1255',
      encodingVisible: true
    };

what else should be done to get the object as array.

like image 751
Vitaly Menchikovsky Avatar asked Sep 05 '25 03:09

Vitaly Menchikovsky


1 Answers

Modify the code in your controller as

     $scope.csv = {
        content: null,
        header: true,
        headerVisible: true,
        separator: ',',
        separatorVisible: true,
        result: null,
        encoding: 'ISO-8859-1',
        encodingVisible: true,
        accept:".csv"
    };

and your in your html

        <ng-csv-import content="csv.content"
            header="csv.header"
            separator="csv.separator"
            result="csv.result"
            accept="csv.accept">
        </ng-csv-import>

$scope.csv.result will now be an array of objects

like image 150
Rahul Arora Avatar answered Sep 07 '25 23:09

Rahul Arora