Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  Billy Moon Apr 7 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? –  Abhi Apr 7 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) –  Lajos Veres Apr 7 at 22:25
    
did you ever figure this out? –  mark1234 Jun 20 at 17:17

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.