2

I've created a local JSON file and am able to get data from the file using

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
}

I've been trying to write an equivalent http POST call by doing a $scope.employees.push, but it is only (understandably) updating the value of the local variable.

How do I update or add values to the original employees.json file?

3
  • you can't do this from client side (it is even beyond the powers of angular to do this). you must write a handler on the server side, and then post data back to it to store int he originating employees.json file. Commented Apr 7, 2014 at 22:05
  • Yes, but the JSON file is stored locally, on the same computer. IS a handler still necessary? If so, can the handler be written in JS or using angular? Commented Apr 7, 2014 at 22:15
  • You can use node.js for example if you prefer javascript. Angular is a client only framework, it doesn't support server side.(AFAIK) Commented Apr 7, 2014 at 22:25

1 Answer 1

0

I don't think it's possible to do that directly from Angular. There are some other sources that you integrate into your app, which you can then have Angular leverage.

You could also just store it as localstorage and access it as you would just about any other object. This would be the method that I'd lean towards more (depending on the size). Otherwise I've always had to have the server-side do it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.