我只想创建一个简单的应用程序,它使用 AngularJS 创建、更新和删除 JSON 文件中的项目。我在网上看过,只找到了使用JavaScript对象编辑或删除JSON类型数据的例子。但我想在 AngularJS 中使用 JSON 作为后端。
是否有任何示例可以将数据发布到 JSON 文件?
提前致谢!
最佳答案
尝试这样的事情:
angular.module('myApp').factory('MyJsonService', function() {
return $resource('/:myFile.json', {myFile: '@file'});
});
然后在你的 Controller 中:
$scope.myJsonContents = MyJsonService.get({file: 'myFilename'}); // keep in mind that this is async though
关于javascript - 如何在 angularjs 中创建和更新 JSON 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17036137/