title: How to update data in a json file in AngularJS?
body: <p>I am using $resource.query() to fetch an JSON array from a JSON file. I can change the data with $save, but the JSON file is not actually updated. Can't find solutions after googling for the entire morning. Not sure if it is possible to update local json file with AngularJS. Any help would be appreciated. </p>
  
  <p>Here is my code. </p>
  
  <pre><code>getData: function(datatype){
      var url = "data/" + datatype + ".json";
      return $resource(url, {}, {
          query: {
              method: "GET",
              isArray: true
          }
      });
  },
  </code></pre>
  
  <p>Call the getData() function in another service function:</p>
  
  <pre><code>var post = this.getData("jobs").query(function(){               
      angular.forEach(staffs, function(staff){
          for(var i = 0; i &lt; post.length; i++){
              if(post[i].id == jobId){
                  alert(post[i].name); //Here it shows the original name "names and numbers"
                  post[i].name = "changed";
                  post[i].$save();    
                  alert(post[i].name); //Here it shows the new name "changed"
                                       //but the data json file is not changed
                  continue;
              }
          }
      });
  });
  </code></pre>
  
  <p>jobs.json:</p>
  
  <pre><code>[
  {
      "id": 554114, 
      "name": "names and numbers",  
      "facility_id": 0
  },
  ...
  ]
  </code></pre>