如何创建和更新angularjs JSON文件? [英] How to create and update JSON file in angularjs?

查看:569
本文介绍了如何创建和更新angularjs JSON文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想创建一个简单的应用程序创造,更新和删除使用AngularJS在JSON文件中的项目。我在网上看了看,才发现例子这需要JavaScript对象进行编辑或删除JSON类型的数据。但是,我想用JSON作为AngularJS后端。

I just want to create a simple app which creates, updates, and deletes items in JSON file using AngularJS. I have looked online, only found examples which takes JavaScript objects to edit, or delete JSON type data. But I want to use JSON as backend in AngularJS.

有哪些可以发布数据JSON文件的例子吗?

Is there any examples out which can post data to JSON file?

在此先感谢!

推荐答案

尝试是这样的:

angular.module('myApp').factory('MyJsonService', function() {
  return $resource('/:myFile.json', {myFile: '@file'});
});

然后在你的控制器:

Then in your controller:

$scope.myJsonContents = MyJsonService.get({file: 'myFilename'}); // keep in mind that this is async though

这篇关于如何创建和更新angularjs JSON文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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