title: When I keep refreshing my angularJS page, the content sometimes shows up, sometimes doesn't
body: <p>I have a page running angularJS. Sometimes, when I open the document, the data that needs to appear only sometimes shows up. When I keep trying to refresh the page, it's pretty much random: sometimes the content appears, sometimes it doesn't.</p>
  
  <p>The section of the code that runs this looks like this:</p>
  
  <pre><code>                &lt;div class="row"&gt;
                      &lt;div class="col-md-12" ng-repeat="(observer,hosts2) in bugDuration"&gt;
                          {{observer}}
                          &lt;div class="row"&gt;
                              &lt;div class="col-md-3" ng-repeat="(host, bugs2) in hosts2"&gt; {{host}} 
                                  &lt;div ng-repeat="(bug, duration) in bugs2"&gt;
                                      {{bug}} for {{duration}} seconds.
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>As you can see, it is using ng-repeat, and my best guess is that when this code is running, the ng-repeat objects, such as <code>bugDuration</code> are empty, so none of it runs. </p>
  
  <p>My script that initializes all of these variables is located after, in my document. Is there something I should do in the controller or whatever so the variables can be refreshed and the content can be shown everytime?</p>
  
  <hr>
  
  <p>Edit</p>
  
  <hr>
  
  <p>Here is the code where bugDuration is initialized:</p>
  
  <pre><code> bugDuration = {};
                      bugTracker = {};
  
                      $.getJSON('../java_output/bugs.json', function (data) {
                          for ( var observer in data ) {
                              bugDuration[observer] = {};
                              for (var host in data[observer]) {
                                  bugDuration[observer][host] = {};
                                  for (var bug in data[observer][host]) {
                                      bugDuration[observer][host][bug] = data[observer][host][bug].duration;    
                                  }
                              }
                          }
  
                          console.log (bugDuration);
                      });
  
  
                      $.getJSON('../java_output/bug_summary.json', function (data) {
                          var numObservers = data.numObservers;
                          delete data['numObservers'];
                          JSONbugsList = data;
                          var bugTracker = {};
                          for (var observer = 1; observer &lt;= numObservers; observer++) {
                              observers.push(observer);
                              observerKeys = Object.keys(data);
                              // observerKeys.splice(observerKeys.indexOf('numObservers'));
                              for (var host in data["observer" + observer]) {
                                  if (hosts.indexOf(host) == -1) {
                                      hosts.push(host);
                                  }
                                  hostKeys = Object.keys(data["observer" + observer]);
                                  for (var bug in data["observer" + observer][host]) {
                                      if (bugs.indexOf(bug) == -1) {
                                          bugs.push(bug);  
                                      }
                                      for (var i in  data["observer" + observer][host][bug]) { 
                                          bugTracker[bug] = true;
                                          var dateVar = data["observer" + observer][host][bug][i];
                                          var intoList = {"observer":observer, "host":host, "bug":bug, "start":(new Date(1000*dateVar.start)), "end":(dateVar.end==null?' the end.':(new Date(1000*dateVar.end)))} 
                                          }
                                  }
                              }
                          }
  
  
  
                         // Removed unimportant stuff here//
  
  
  
                          $scope.$apply();
                          $scope.hostsS = hosts;
                          $scope.bugsS = bugs;
                          $scope.observersS = observers;
                          $scope.JSONbugsList = JSONbugsList;
                          $scope.hostKeys = hostKeys;
                          $scope.observerKeys = observerKeys; 
                          $scope.start = 'start';
                          $scope.end = 'end';
                          $scope.bugDuration = bugDuration;
                          $scope.$apply();
  </code></pre>