title: How to initialize array before $scope will be loaded in AngularJS application
body: <p>I have problem with my AngularJS application. In my html view, i have list that contains JavaScript objects.</p>
  
  <pre><code>&lt;div ng-init="initWeek()" ng-controller="TableController"&gt;
  &lt;div id="TaskImages"&gt; &lt;div ng-repeat="task in taskList"&gt; &lt;div id="TaskImg" &gt;&lt;br&gt;      {{task.title}}&lt;br&gt;{{task.start}} &lt;/div&gt;   &lt;/div&gt;&lt;/div&gt;  
  </code></pre>
  
  <p></p>
  
  <p>I set taskList by using the Jquery/Ajax, which gets all task object from server.</p>
  
  <pre><code>function getTaskFromServer() {
  
  $.ajax({
  
      type : "POST",
      url : "main_page",
  
      success : function(data) {
  
          var taskList = $.parseJSON(data);
  
          week[0].push(taskList[0]);
  
      },
  
  }); 
  </code></pre>
  
  <p>My controller looks like this:</p>
  
  <pre><code>$scope.initWeek = function() {
  
      getTaskFromServer();
  };
  $scope.taskList = week[currentlySelectedDay-1];
  </code></pre>
  
  <p>When I load application, the list "week" contains objects but in html view can see text.</p>
  
  <p>I think that $scope.taskList is loaded before list "week".</p>
  
  <p>For example, when I use: </p>
  
  <pre><code>$scope.initWeek = function() {
  
      getTaskFromServer();
      alert(week[0].lenght);
  };
  $scope.taskList = week[currentlySelectedDay-1];
  </code></pre>
  
  <p>Site displays alert and when i click Ok the text from taskList is a an website.</p>