Update external json file value

By : Becky
Source: Stackoverflow.com
Question!

I have an external file with a value 0. I need to be able to increase the value each time this file is accessed?

json file.

number = '[{"num" : 0}]'

How can I update the value of this external json file from js?

var mydata = JSON.parse(number);
alert(mydata[0].num);
//how add +1 to this value and update the external file?
By : Becky


Answers

since you have the file on the server side, so to update the number every time you access the file, you need a server side programming like PHP or python etc. Then you can use ajax get or post request to that file and on request that file php will increase the number.

The way you can send request to the file using jquery:

$.get("YOUR_JSON_FILE", function(data, status){
    // response and data you get from server
});

you can take a deep look on it in more details in the link below : Jquery Ajax Request



They just assigned to your class object. So try to put in component some data for bindings and then try to access.

class MyController implements IMyController {
 $onInit(): void {
   console.log(this.data, this.label);
 } 
 public myMethod(): void {
 }
}

angular.module('mymodule').component(
  'myCmp', {
    controller: MyController,
    controllerAs: 'vm',
    templateUrl: 'myCmp.component.html',
    bindings: {
      data: '=',
      label: '='
    }
});
By : Mikki


This video can help you solving your question :)
By: admin