Greg Sithole
Greg Sithole

Reputation: 145

$viewContentLoaded Check if it's Successful

I wanted to ask about $viewContentLoaded... I'm building an Ionic app, and wanted to implement $ionicLoading, so that before the content is loaded, it shows a loading icon.The following is the line of code that is in my controller:

$ionicLoading.show({
 template: '<ion-spinner></ion-spinner>'+
        '</br></br><p>Loading...</p>',
    animation: 'fade-in',
    showBackdrop: true,
    maxWidth: 300,
    showDelay: 0
  });

   $scope.$on('$viewContentLoaded', function()
  {
    $timeout(function () {
      $ionicLoading.hide();
      }, 2000);
  });

This works because I used the $timeout, but I wanted to to stop the $ionicLoading when the page has Loaded the content.

Please help?

Upvotes: 1

Views: 166

Answers (1)

VinceOPS
VinceOPS

Reputation: 2720

Using $timeout ensures that a new $digest cycle is executed just after your code. Did you try without specifying a delay (instead of 2000) ? (default delay is 0). I feel like it will work too.

Otherwise, I'd recommend to use Ionic Views' LifeCycle Events, like $ionicView.enter which sounds appropriate for your need.

Upvotes: 1

Related Questions