title: Bind json to HTML table with AngularJS on page load
body: <p>I have a simple proof-of-concept I'm using as a base to learn some AngularJS.  The code displays some JSON data in an HTML table, as follows:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div ng-app="myApp"&gt;
      &lt;div ng-controller="PeopleCtrl"&gt;
          &lt;p&gt;Click &lt;a ng-click="loadPeople()"&gt;here&lt;/a&gt; to load data.&lt;/p&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;th&gt;Id&lt;/th&gt;
                  &lt;th&gt;First Name&lt;/th&gt;
                  &lt;th&gt;Last Name&lt;/th&gt;
              &lt;/tr&gt;
              &lt;tr ng-repeat="person in people"&gt;
                  &lt;td&gt;{{person.id}}&lt;/td&gt;
                  &lt;td&gt;{{person.firstName}}&lt;/td&gt;
                  &lt;td&gt;{{person.lastName}}&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>var mockDataForThisTest = "json=" + encodeURI(JSON.stringify([
      {
      id: 1,
      firstName: "Peter",
      lastName: "Jhons"},
  {
      id: 2,
      firstName: "David",
      lastName: "Bowie"}
  ]));
  
  
  var app = angular.module('myApp', []);
  
  function PeopleCtrl($scope, $http) {
  
      $scope.people = [];
  
      $scope.loadPeople = function() {
          var httpRequest = $http({
              method: 'POST',
              url: '/echo/json/',
              data: mockDataForThisTest
  
          }).success(function(data, status) {
              $scope.people = data;
          });
  
      };
  
  }
  </code></pre>
  
  <p>A fiddle is here: <a href="http://jsfiddle.net/TUJ9D/" rel="noreferrer">http://jsfiddle.net/TUJ9D/</a></p>
  
  <p>This works nicely; when you click the link, it calls 'loadPeople' and the json is pulled into the table.  However, what I'd like to do is bind this when the page loads, so the user doesn't have to manually click the link to see the data in the table.</p>
  
  <p>I wondered what the best way to do this is?  Instinct is telling me to call the function with jquery on page load, but then I don't know if that's a good approach or whether Angular could do this in a better way itself.</p>
  
  <p>Thanks folks.</p>