I wrote an ExportService.js
in AngularJS that submits HTTP POST request to remote service for downloading data. When the data is returned from remote service, I am struggling how to let the browser download the resolved promise (data). For example, my code basically is following:
ExportService.requestData(); //this returns a promise object.
In my controller, the code below waits for the promise to resolve/fail.
ExportService.requestData().then(function(data) {
//how to process the data for download here?
$log.info(JSON.stringify(data)); //print out the data
}).catch(function(err) {
//handle error here
}).finally(function(complete){
//complete the request here
});
I think, essentially, how to convert the data stream to a file and let it download in the browser.