title: unable to use rootScope inside window.onnotification
body: <p>I am trying to use rootScope as global so that same can be retrieved in controller.</p>
  
  <p>app.js:</p>
  
  <pre><code>angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives'])
  .run(function($ionicPlatform,$rootScope) {
    $ionicPlatform.ready(function() {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      if (window.cordova &amp;&amp; window.cordova.plugins &amp;&amp; window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        cordova.plugins.Keyboard.disableScroll(true);
      }
      if (window.StatusBar) {
        // org.apache.cordova.statusbar required
        StatusBar.styleDefault();
      }
  
      pushNotification = window.plugins.pushNotification;
      pushNotification.register(
      onNotification,
      errorHandler,
    {
      'badge': 'true',
      'sound': 'true',
      'alert': 'true',
      'ecb': 'onNotification',
      'senderID': '999999999999',
    }
      );
  
  
    });
  })
  
  window.onNotification = function(e){
  
        switch(e.event){
          case 'registered':
            if(e.regid.length &gt; 0){
  
              var device_token = e.regid;
  
                alert('registered :'+device_token);
                $rootScope.devicetoken = device_token;
  
            }
          break;
  
          case 'message':
            alert('msg received: ' + e.message);
            break;
  
          case 'error':
            alert('error occured');
          break;
  
        }
  };
  
  window.errorHandler = function(error){
    alert('an error occured');
  }
  </code></pre>
  
  <p>I am getting device_token and getting in alert. but it is not going inside rootScope to use it in controller.</p>
  
  <p>Controller.js:</p>
  
  <pre><code>angular.module('app.controllers', [])
  
  .controller('onWalletWelcomesCtrl', function($scope, $ionicModal,User,$ionicLoading,$rootScope) {
  
      $ionicModal.fromTemplateUrl('signup-modal.html', {
        id: '1', // We need to use and ID to identify the modal that is firing the event!
        scope: $scope,
        backdropClickToClose: false,
        animation: 'slide-in-up'
      }).then(function(modal) {
        $scope.oModal1 = modal;
      });
  
      $scope.proceed = function(){
          alert($rootScope.devicetoken);
          $ionicLoading.show({template: '&lt;ion-spinner icon="android"&gt;&lt;/ion-spinner&gt;'});
  
      }
  
  })
  </code></pre>
  
  <p>I am getting undefined while alerting in proceed function.
  How should I use rootScope in window.onNotification. My main intention is to pass the devicetoken to controller. Please let me the best practice to share the variables.</p>
  
  <pre><code>angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives'])
  .run(function($ionicPlatform,$rootScope) {
    $ionicPlatform.ready(function() {
  
      if (window.cordova &amp;&amp; window.cordova.plugins &amp;&amp; window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        cordova.plugins.Keyboard.disableScroll(true);
      }
      if (window.StatusBar) {
        // org.apache.cordova.statusbar required
        StatusBar.styleDefault();
      }
  
      pushNotification = window.plugins.pushNotification;
      pushNotification.register(
      onNotification,
      errorHandler,
    {
      'badge': 'true',
      'sound': 'true',
      'alert': 'true',
      'ecb': 'onNotification',
      'senderID': '9999999999',
    }
      );
  
    });
  })
  
  window.onNotification = function(e){
  
        switch(e.event){
          case 'registered':
            if(e.regid.length &gt; 0){
  
              var device_token = e.regid;
  
              alert('registered :'+device_token);
              $rootScope.devicetoken = "hi";
              $scope.$apply();
  
            }
          break;
  
          case 'message':
            alert('msg received: ' + e.message);
  
          break;
  
          case 'error':
            alert('error occured');
          break;
  
        }
  };
  
  window.errorHandler = function(error){
    alert('an error occured');
  }
  </code></pre>
  
  <p>Still I am getting undefined while alerting in controller.</p>