title: Defining global functions and properties accessible by AngularJS factory and controllers
body: <p>I'm working on an AngularJS app. When an error is thrown, I want to do some custom handling of the error. To do that, I've done the following:</p>
  
  <pre><code>var myApp = angular.module('myApp', []);
  myApp.factory('$exceptionHandler', function($rootScope) {
    return function(exception, cause) {
      try {
        console.log('Unhandled error happening in version ' + $rootScope.APP_VERSION);
        console.log('Error happened at ' + $rootScope.getFormattedDateTime());
      } catch (uex1) {
        console.log('Unable to log unhandled exception.');
      }
    };
  });
  
  myApp.run(function ($rootScope) {
    $rootScope.APP_VERSION = '1.0';
    $rootScope.getFormattedDateTime = function() {
      return '--';
    };
  });
  </code></pre>
  
  <p>When I run this code, I get <a href="https://docs.angularjs.org/error/%24injector/cdep?p0=%24exceptionHandler%20%3C-%20%24rootScope" rel="nofollow">this error</a>. I guess I can't add <code>$rootScope</code> to factory declarations. If that's the case, how do I define globally accessible functions and variables so that I can access them in my controllers as well as from this factory?</p>
  
  <p>Thank you so much for any assistance you can provide.</p>