0

I'm a newbie in ionic frameworks, I'm developing an app in which I need to convert the data which is coming from $HTTP.post method, into CSV format and on button click it should download in .xsl format, I already searched so many articles on it but not worked.. please help me... Thanks.

1 Answer 1

0

There is a similar question here.. Angular.js generate csv file from json data

If you're using ionic, I would assume angular, and therefore recommend this directive that turns arrays and objects into downloadable CSV files.

https://github.com/asafdav/ng-csv

If you don't want to read the accepted answers. Here's the sklinny.

var myapp = angular.module('myapp', ['ngSanitize', 'ngCsv'])

Add ng-csv directive to the wanted element, example:

<button type="button" ng-csv="getArray" filename="test.csv">Export</button>

In your controller, getarray is just your array (the json you'd get back from your request).

 $scope.getArray = [{a: 1, b:2}, {a:3, b:4}];
Sign up to request clarification or add additional context in comments.

2 Comments

how to add cordovaFile plugin...? I tried but Its showing an error..in injector
@anjalijibhakate ngcordova.com/docs/plugins/file , Ngcordova plugins work on device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.