$ionicPlatform.ready event is firing twice

Hi All,
I’m new to Ionic and I’m having an I’m having a problem with the $ionicPlatform.ready event firing twice. I have the code below in my app.controller file. I have set a break point on the alert in order to see the stacktrace and it looks like the exact same stacktrace each time.

Does anyone know how to prevent this event from firing twice? Or is there another event I should use to fire off my code when the device is ready? Here’s my code (nothing special):

$ionicPlatform.ready(function () {
alert(‘ionic is ready event fired’);
});

Update: I noticed that when I removed $rootScope, from my controller the $ionicPlatform.ready event fired only once. I’m working on refactoring my code so that I don’t need $rootScope in the controller, but does anyone know why having it would cause the platform ready event to fire twice?

Did you ever sort this out? I’m having the same issue. this is in my controller.

$ionicPlatform.ready(function() {

     if(sessionStorage.getItem('featured') == null) {
        alert('get data'); 
      }else {
        alert('cached');
        $ionicLoading.hide();
        $scope.featured = JSON.parse( sessionStorage.getItem('featured') );
      }
    
  });

both of my alerts fire twice too. I removed the rootScope and I still have the issue.
I decided to do a google : and found this,

My template was also calling my controller.

Yes, I had added a an ‘ng-controller’ to my view and it caused the event to fire twice. Try doubling checking to see if you have the same issue. Also, are you doing any nested views? Can you please post your view and the complete code for the controller?

I fixed this with the link above. I specified the controller in the view and that was the culprit.

I had this problem as well, but it was more easily solved for me. I was using the new “ionic serve --lab” so it was running twice, once for each version of the app. I thought it was running twice in one of the apps. When I ran “ionic serve” (without the --lab flag) it only ran once.

3 Likes

This makes sense as I couldn’t figure why I was getting a console.log twice using ionic serve --lab…Thanks for saving my day