$scope.downloadXmlFile = function (xml) { var link = document.createElement('a'); link.href = "data:text/xml;charset=utf-8," + encodeURIComponent(xml); link.download = "file.xml"; link.click(); }