0

How do I update local json file using angularjs. My file name is data.json which is location in project folder.

I tried this below way

var data = [{
  "Numbers": {
      "Number": {
          "_Id": "1",
          "__text": "201"
      }
  }
}];

var jsonFileName = "data.json"

factory.updateJsonDataByFileName = function (jsonFileName, data) {
    $http.post(jsonFileName, data).then(function successCallback(response) {
        var jsonResult = response.data;
        deferred.resolve(jsonResult);
    }, function errorCallback(error) {
        deferred.reject(error);
    });
    return deferred.promise;
}

My JSON File looks like this below

{
    "Numbers": {
        "Number": {
            "_Id": "1",
            "__text": "200"
        }
    }
}
georgeawg
  • 48,608
  • 13
  • 72
  • 95
user1030181
  • 1,995
  • 5
  • 26
  • 56
  • What error message does the Developer Console show? – georgeawg Feb 05 '19 at 20:53
  • no error message...data is not updated. – user1030181 Feb 05 '19 at 20:56
  • There's no native API* for File System access in browsers. For more information, see [Local JavaScript - write to local file](https://stackoverflow.com/questions/5349921/local-javascript-write-to-local-file). – georgeawg Feb 05 '19 at 21:03
  • Avoid the [deferred Anti-Pattern](https://stackoverflow.com/questions/30750207/is-this-a-deferred-antipattern). – georgeawg Feb 05 '19 at 21:17
  • There is no way to update local file. initiate JSON in local storage and update it with response data which is come from HTTP request. But if your trying to get dynamic data, use database and get data from HTTP request. – Mahesh Sanjeewa Feb 06 '19 at 10:01

0 Answers0