17

In angularjs I created some service that loads JSON object:

// used to load table from json file instead ajax
myModule.factory('Items', ['$http', function($http){
    var Url   = "src/utils/some.json";
    var Items = $http.get(Url).then(function(response){
     return response.data;
  });
  return Items;
}]);

And in controller I can call it like:

Items.then(function(data){
  $scope.items = data;
});

As You can see I load some.json file.

What should be flow to do the same with CSV file?

in my case $scope.items is a list of objects.

Does someone know how to get CSV data by using $http.get or other way?

||||||
24

You have to parse the CSV file into an array. You can see this question for some alternatives: Javascript code to parse CSV data

Then you'll end up with something like this:

myModule.factory('Items', ['$http', function($http){
  var Url   = "src/utils/some.csv";
  var Items = $http.get(Url).then(function(response){
     return csvParser(response.data);
  });
  return Items;
}]);
||||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.