typescript 在本地使用 angular2 打字稿写入本地文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41547945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Write to a local file using angular2 typescript locally
提问by keerthee
How to write to an external file using typescript in angular2 (client side) ? I need to write some text into a file in some format. Can anyone help? I googled and saw only how to do using node library or javascript blob. Is there a typescript way of doing it?
如何在 angular2(客户端)中使用打字稿写入外部文件?我需要以某种格式将一些文本写入文件中。任何人都可以帮忙吗?我用谷歌搜索,只看到如何使用节点库或 javascript blob。有没有打字稿的方式来做到这一点?
回答by Günter Z?chbauer
You can't write to local files. The code runs in the browser and the browser will prevent access to the local file system. What you can do is to create a download link with a data url, that the user clicks and saves to a file.
您不能写入本地文件。代码在浏览器中运行,浏览器将阻止访问本地文件系统。您可以做的是创建一个带有数据 url 的下载链接,用户单击该链接并将其保存到文件中。
See also How to read and write into file using JavaScriptfor a limited way to writ to local files.
另请参阅如何使用 JavaScript 读取和写入文件,了解写入本地文件的有限方式。