1

In my ionic app I have the app.run function and a device ready function inside it:

app.run(function($rootScope, $ionicPlatform, $cordovaPush) {
    document.addEventListener("deviceready", function(){

    }, false);
})

When I declare a rootScope variable in the run function like below the variable is available in all controllers.

app.run(function($rootScope, $ionicPlatform, $cordovaPush) {

    $rootScope.myvariable = 'teststring';

    document.addEventListener("deviceready", function(){

    }, false);
})

When I place the rootScope variable inside the deviceready function the rootScope variable is not available anymore

app.run(function($rootScope, $ionicPlatform, $cordovaPush) {
    document.addEventListener("deviceready", function(){

        // I need this variable here because it's a value generated by a function that only works inside the deviceready function

        $rootScope.myvariable = 'teststring';

    }, false);
})

How can I make the rootscope variable inside the deviceready function available for all my controller ?

user1242574
  • 1,257
  • 3
  • 12
  • 29
  • myvariable will still be available but only after deviceready. So when you try to access it device is just not ready yet.What are you trying to do with that variable. – John Jul 06 '15 at 20:14
  • I need the variable throughout my app in other functions in different controllers. The variable contains device info and unfortunately I can only retrieve that information in that location and no where els. It's about the device token for the push notification service. – user1242574 Jul 08 '15 at 12:53
  • Checkout this question http://stackoverflow.com/questions/21556090/cordova-angularjs-device-ready – John Jul 08 '15 at 12:57

0 Answers0