title: Using window.onload in AngularJS service
body: <p>I'm using AngularJS 1.6 to create a game that relies on some images. The game is separate from Angular for the most part, and instantiated by a service, before any of the controllers are run. I want the game to be instantiated by a service so that I can expose it to other controllers, which do interact with the game in some capacity. I use $window.onload, but it only works when the page first loads. When I refresh the page, the event doesn't fire, presumably because the browser is getting the images from the cache. </p>
  
  <p>I've considered using document.ready, but this will occasionally cause problems when the images haven't loaded quickly enough.</p>
  
  <p>I've tried jQuery, vanilla JS, and Angular's syntax:</p>
  
  <pre><code>$(window).on('load', function() {});
  $window.onload = function();
  angular.element($window).on('load', function() {});
  </code></pre>
  
  <p>Any advice would be greatly appreciated. This is what my code basically looks like.</p>
  
  <pre><code>// Game Service (game state, game logic and game loop)
  gameApp.service('theGame', function($log, $document, $window, 
  $location, $timeout, $interval) {
  
  
      $window.onload = function() {
          // Initialize a new Game object
          var game = new Game();
          game.initGame();
      };
  
  });
  </code></pre>