I am new to angularJS.I want to download JSON file.It is working in chrome but not in Edge and Safari.In safari file is opening in browser only. Thanks for reading. Plz reply.
function itemExport() {
var a = document.createElement("a");
document.body.appendChild(a);
//a.style = "display: none";
if ($scope.selectedRows.length > 0) {
commonFactory.itemExport($scope.selectedRows, $scope.className).then(function (data) {
var json = JSON.stringify(data.data),
blob = new Blob([json], {type: "octet/stream"});
//url = window.URL.createObjectURL(blob);
var encodedUri = encodeURI("data:text/plain;charset=utf-8," + json);
a.setAttribute("href",encodedUri);
if ($scope.selectedRows.length === 1) {
commonFactory.getInstanceByUID($scope.domainUID, $scope.classUID, $scope.className, $scope.selectedRows[0], $scope.isCoreComponents).then(function (inst) {
a.setAttribute("download", inst[0]._fields[0].properties.Name+".json");
a.click();
window.URL.revokeObjectURL(url);
});
} else {
a.download = $scope.className+".json";
a.click();
window.URL.revokeObjectURL(url);
}
});
} else {
toastrFactory.warning('Please select at least one item to Export', 'Warning');
}
}