I got help to save json as file in client side here. Code is very short as in this fiddle.
var a = document.createElement('a');
a.download = "backup.json";
a.href = url;
a.textContent = "Download backup.json";
document.getElementById('content').appendChild(a);
I was trying to create an angularjs directive so that it calls a method in scope to get the data. Along this line.
module.directive('myDownload', function ($compile) {
return {
restrict:'E',
scope:{ getData:'&getData'},
link:function (scope, elm, attrs) {
elm.append($compile(
'<a class="btn" download="backup.json"' +
'href=' + scope.getData() + '>' +
'Download' +
'</a>'
)(scope));
}
};
});
This doesn't work. How can make the linked fiddle into a directive?