An AngularJS simple directive that turns arrays and objects into downloadable CSV files,
-
Add ng-csv.min.js to your main file (index.html)
-
Set
ngCsv
as a dependency in your module
var myapp = angular.module('myapp', ['ngCsv'])
- Add ng-csv directive to the wanted element, example:
<button type="button" ng-csv="getArray()" filename="test.csv">Export</button>
Just provide csv-header attribute.
<button type="button" ng-csv="getArray()" csv-header="['Field A', 'Field B', 'Field C']" filename="test.csv">Export</button>
You can check out this live example here: http://jsfiddle.net/asafdav/dR6Nb/