简体   繁体   English

以角度4读取和写入文件

[英]Read and Write to file in angular 4

I am trying to create an offline Todo List in Angular 4 . 我正在尝试在Angular 4中创建一个离线待办事项列表

But I am not able to find any way to store data in a file at Client side using javaScript or Angular. 但是我找不到任何使用javaScript或Angular将数据存储在客户端文件中的方法。

I am using localStorage of browser right now but it is very slow and it makes my program browser dependent. 我现在正在使用浏览器的localStorage,但是它非常慢,并且使我的程序依赖于浏览器。

please provide a way to create files at client side or any suggestions 请提供一种在客户端创建文件的方法或任何建议

To download file or save file

    /**
     * Method is use to download file.
     * @param data - Array Buffer data
     * @param type - type of the document.
     */
    downLoadFile(data: any, type: string) {
        var blob = new Blob([data], { type: type.toString() });
        var url = window.URL.createObjectURL(blob);
        window.open(url);
    }

What you are trying is not possible and it should not be possible for security reasons. 您尝试的操作是不可能的,并且出于安全原因,这应该是不可能的。 I would not expect any webpage would have access to my file system. 我不希望任何网页都可以访问我的文件系统。

If you are building an offline application and it is a desktop app you might try to check electron . 如果您要构建脱机应用程序,并且它是桌面应用程序,则可以尝试检查电子 But that's only if it is a desktop application, if it runs in the browser then it is just not possible. 但这仅是桌面应用程序,如果它在浏览器中运行,那就不可能了。

We can use IndexDb or websql for offline application. 我们可以使用IndexDb或websql进行脱机应用程序。

For more details you can check on following URL 有关更多详细信息,您可以检查以下URL

https://www.codeproject.com/Articles/820391/A-Very-Simple-Example-of-HTML-OFFLINE-Database-ind https://www.codeproject.com/Articles/820391/A-Very-Simple-Example-of-HTML-OFFLINE-Database-ind

Hope this will Help :) 希望这会有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM