在本地使用angular2打字稿写入本地文件 [英] Write to a local file using angular2 typescript locally

查看:115
本文介绍了在本地使用angular2打字稿写入本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在angular2(客户端)中使用Typescript写入外部文件?我需要以某种格式将一些文本写入文件.有人可以帮忙吗?我用谷歌搜索,仅看到了如何使用节点库或javascript blob.有打字稿的方法吗?

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?

推荐答案

您无法写入本地文件.该代码在浏览器中运行,浏览器将阻止访问本地文件系统.您可以做的是创建一个带有数据URL的下载链接,用户单击该链接并将其保存到文件中.

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.

另请参见如何使用JavaScript读写文件用于写入本地文件的有限方式.

See also How to read and write into file using JavaScript for a limited way to writ to local files.

这篇关于在本地使用angular2打字稿写入本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆