title: AngularJS - why is $apply required to properly resolve a $q promise?
body: <p>I'm trying to write a small service in my angular app which will enable me to pick config parameters specified in global Javascript objects. I don't want to attempt accessing the global config object unless the document is ready (because I cannot guarantee the order in which script elements will be inserted in the HTML).</p>
  
  <p>However, I can't understand why I need the call to <code>$apply</code> for the resolution to actually propagate to the <code>then</code> callback. </p>
  
  <pre><code>myModule.service('GlobalConfigService', ['$q', '$rootScope', function($q, $rootScope) {
      var def = $q.defer();
      $(document).ready(function() {
          def.resolve(MyConfig.val);
          $rootScope.$apply();
      });
  
      def.promise.then(function () {
          console.log('I am called only when $apply() is called. Why?');
      });
  
      return def.promise;
  }]);
  </code></pre>