Angular directive for exporting and downloading JSON data into a CSV file
Code generation based off of this example.
bower install ng-csv-download
Demo is running in Plunker here..
- npm install
- npm start
- http://127.0.0.1:8080
(If you're using Markdown pad to view this README, open the link in an external browser)
In the app
ngModule.controller(myApp, ['tld.csvDownload'])
In your HTML
<csv-download
column-header-array="myHeaderDataArray"
input-array="myInputArray"
label="{{myLabel}}"
filename="{{myFilename}}"></csv-download>
Optional
Bound Variable: e..g : $scope.myHeader = []; column-header-array="myHeader"
If not defined, then defaults to the keys in the inputArray.
This is a bound variable for an array of column headers, the key matches the data array keys, the values are the headers.
Required
Bound Variable: e..g : $scope.myData = []; input-array="myData"
Contains an array of elements. Each element is a JSON with key/value pairs. If the column-header-array is not included, the keys become the column headers.
Optional
String variable: e.g. $scope.myLabel; label="{{myLabel}} or label="My Text"
Display text for the download link. Defaults to "Download Data".
Optional
String variable: e.g. $scope.myFilename; label="{{myFilename}} or label="MyFile.csv"
Name of the CSV file being downloaded. Defaults to "export.csv".