Angular4/5: 如何使用打字稿创建文件夹、文本文件并将数据写入该文件

Angular4/5: how to create folder, text file and write data into that file using typescript

我需要在 angular5 中创建文件夹、文本文件并将数据写入该文件,使用 typescript.This 是在文本文件中写入错误。 angular可以吗?

提前致谢。

正如 Osman Cea 所说,这不能在客户端完成。您可以使用 Blob and URL.createObjectURL 创建文件。但是您不能保存文件,因为那样会引起很大的安全问题。

既然要记录错误,可以post把错误传到服务器,然后存到数据库或文件系统中。这意味着您需要在服务器端使用一些框架,例如 PHP、ASP.NET Core ...

如果您使用 Google 分析,另一种选择(如果您真的想避免我不推荐的服务器框架)是使用 Google 分析 API。我曾经使用 API.

将客户端错误记录到 Google 分析
ga('send', {
  hitType: 'event',
  eventCategory: 'Error',
  eventAction: window.location.href,
  eventLabel: your_error_object
});