简体   繁体   English

如何从 Angular 向客户端 json 文件添加或编辑?

[英]How to add or edit to a client side json file from Angular?

I am working with Angular 8. I have 2 JSON files on the client-side which are basically an array of JSON objects, from where I read and use in my component.我正在使用 Angular 8。我在客户端有 2 个 JSON 文件,它们基本上是一个 JSON 对象数组,我从中读取和使用我的组件。 I want to add (or edit) an object in those JSON files using angular only(without sending it to backend) and then make sure component is able to use it.我想仅使用 angular 在那些 JSON 文件中添加(或编辑)一个 object(不将其发送到后端),然后确保组件能够使用它。 Is it possible through angular?是否可以通过angular? Or will I have to use a typescript file and store all information there?还是我必须使用 typescript 文件并将所有信息存储在那里?

You can not do file operation only using Angular framework.您不能仅使用 Angular 框架进行文件操作。 You can use localStorage or in-memory-db to do that.您可以使用localStoragein-memory-db来执行此操作。

https://www.npmjs.com/package/angular-in-memory-web-api https://www.npmjs.com/package/angular-in-memory-web-api

Angular doc for in memory db memory db 中的 Angular 文档

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

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