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.
Here is my code.
getData: function(datatype){
var url = "data/" + datatype + ".json";
return $resource(url, {}, {
query: {
method: "GET",
isArray: true
}
});
},
Call the getData() function in another service function:
var post = this.getData("jobs").query(function(){
angular.forEach(staffs, function(staff){
for(var i = 0; i < 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;
}
}
});
});
jobs.json:
[
{
"id": 554114,
"name": "names and numbers",
"facility_id": 0
},
...
]