title: $rootScope Event not working Angularjs
body: <p>I have declared <strong>$rootScope.$on</strong> function under the <strong>myApp.run</strong> to check token value in every authenticated page.but its not working.I do not understand why its not working.Please help me.</p>
  
  <p>app.js</p>
  
  <pre><code>myApp.run(['$rootScope','$state', '$location', 'loginService', function ($rootScope,$state, $location, loginService) {
  
      console.log(" under run =&gt; ");
      $rootScope.$on('routeChangeStart', function (event, next, current) {
          /*If route is authenticated then check if the user has access token, else return to login screen*/
  
          console.log(event);
  
          if (next.$$route.authenticated) {
  
              var userAuth = loginService.getUserToken();
              console.log(" usertoken =&gt; " +userAuth);
              if (!userAuth) {
                  $location.path("/");
              }
          }
  
      });
   }]);
  </code></pre>
  
  <p>code print on console <strong>"under run =>"</strong> but it is not printing <strong>event</strong> object and also not check if condition.</p>