I have an application where I make a http request from angularjs to a Java Application to fetch the data from DB.
I am getting the json as reponse in json array format.
[ {
"pumpId": 33,
"pVVoltage": "214",
"pVCurrent": "0",
"epochTime": 1482690480000
},
{
"pumpId": 33,
"pVVoltage": "214",
"pVCurrent": "0",
"epochTime": 1482690480000
}
]
Task: On clicking Download button, angularjs controller can convert json object array to csv and give option to download this file to user.
HTML:
<button type="button" class="btn btn-primary btn-sm" ng-click="get_report(report_from_time, report_to_time)">Download</button>
get_report() have the json data.
PumpService.getReport($scope.id, $scope.timestamp_report_from_time, $scope.timestamp_report_to_time).success(function (data) {
$scope.reportData = data;
}).error(function (error) {
console.error('ERROR OCCURED:', +error);
})
What I need:
Way to convert the json array into csv file in angularjs controller.
On clicking Download button, this converted csv file can be downloaded into local system. Any guidance would be highly appreciated.