【发布时间】:2014-04-07 21:47:30
【问题描述】:
我创建了一个本地 JSON 文件,并且能够使用
从文件中获取数据app.controller('appCtrl', function($scope, $http){
$http.get('employees.json').success(function(data){
$scope.employees=angular.fromJson(data.employees);
console.log($scope.employees);
}); //this is where the data from the json file is taken and stored into $scope.employees. works fine
}
我一直在尝试通过$scope.employees.push 编写等效的http POST 调用,但它只是(可以理解地)更新局部变量的值。
如何更新或添加原始employees.json 文件的值?
【问题讨论】:
-
您不能从客户端执行此操作(它甚至超出了 Angular 的能力)。您必须在服务器端编写一个处理程序,然后将
post数据返回给它以将其存储在原始employees.json文件中。 -
是的,但是 JSON 文件存储在本地,在同一台计算机上。仍然需要处理程序吗?如果是这样,处理程序可以用 JS 编写还是使用 angular 编写?
-
如果您更喜欢 javascript,可以使用 node.js。 Angular 是一个仅限客户端的框架,它不支持服务器端。(AFAIK)
-
你有想过这个吗?
标签: javascript json angularjs