Set global variable at $ionicPlatform.ready and access inside a controller


#1

Hi, I’m new at ionic and angularjs and I really need to set a variable/array inside $ionicPlatform.ready(function() { in app.js and be able to access it inside my controller. Just this.

I’ve tried $rootScope but it returns undefined.

I know It’s very simple problem but it’s hard to google it.
I’m posting this here because I went through inumerous topics on this forum as well at stackoverflow.com

Any help will be welcome


#2

Does this* gives you “undefined”?

app.run(function($ionicPlatform, $rootScope){    
  $ionicPlatform.ready(function() {
    console.log($rootScope); // *
  });
});

#3

sigh …it’s working now. As I said I’m a noob on this area. I was refreshing the page on the browser instead of going through the whole process of initializing the app.

$rootScope works, thanks for replying @joseadrian


#4

Hello,

I face same problem. Have anyone idea?

Thanks David


#5

declare $rootScope service inside run(function($rootScope){}) instead of declaring in $ionicPlatform.ready(function($rootScope) {})