title: AngularJS with PHP to get and update a link
body: <p>I am trying to use AngularJS to access a PHP variable. Here is my HTML and Angular code: </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"&gt;&lt;/script&gt;
  &lt;body&gt;
  
  &lt;div ng-app="myApp" ng-controller="mainCtrl"&gt;
  
  Your Link: &lt;div&gt; &lt;span ng-bind="fetchLink.link"&gt;&lt;/span&gt;&lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;script&gt;
  
    angular.module('myApp', [])
      .controller('mainCtrl', ['$http', function($http) {
        var self = this;
        self.link = "";
        self.newTodo = {}; //Keys (as in key: value pairs) are automatically created when declared in form
        var fetchLink = function() {
          return $http.get('link.php').then(
              function(response) {
            self.link = response.data;
          }, function(errResponse) {
            console.error('Error while fetching notes');
          });
        };
  
  }]);
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is my PHP: </p>
  
  <pre><code>&lt;?php 
  { $link = 0x00;
      "link":[{$link}];
      $link= ($link + 1);
  }
  ?&gt;
  </code></pre>
  
  <p>I am trying to use the Angular code to access the 'link' variable that has to be updated each time it is accessed by any user (a hexidecimal value that is increased by 1). This is so that each user gets a unique link which they can access and share with their friends. When i preview the html page it just says your link: without any value next to it. I also thought about using a JSON object which I believe plays nicely with Angular, but I don't know if JSON objects can be updated with each use (because they are a client-side object, not server side). </p>