$http({
url : '/path/to/your/API',
method : 'POST',
params : {},
headers : {
'Content-type' : 'application/pdf',
},
responseType : 'arraybuffer'
}).success(function(data, status, headers, config) {
// TODO when WS success
var file = new Blob([ data ], {
type : 'application/csv'
});
//trick to download store a file having its URL
var fileURL = URL.createObjectURL(file);
var a = document.createElement('a');
a.href = fileURL;
a.target = '_blank';
a.download = 'yourfilename.pdf';
document.body.appendChild(a);
a.click();
}).error(function(data, status, headers, config) {
//TODO when WS error
});
7:03 PM
$scope.saveAsPDF = function() {
var form = document.createElement("form");
form.setAttribute("action", "some/path/to/the/file");
form.setAttribute("method", "get");
form.setAttribute("target", "_blank");
var hiddenEle1 = document.createElement("input");
hiddenEle1.setAttribute("type", "hidden");
hiddenEle1.setAttribute("name", "some");
hiddenEle1.setAttribute("value", value);
form.append(hiddenEle1 );
form.submit();
}
The above code is not working