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?
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write.
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;
}]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With