Add event listener online

hi, I have designed an app that connects to a rest wordpress , and it all works , I now have the problem that I have to manage when the application is connected or not to the Internet , I did a test with the addListener event ( online ) , managed by controller…appena I open the app makes a chimata rest , I attach my code

controller('AppCtrl',function($scope, $http,$sce,$timeout,$ionicLoading){

     document.addEventListener("online", function() {
       // Setup the loader
  $ionicLoading.show({
    content: 'Loading',
    animation: 'fade-in',
    showBackdrop: true,
    maxWidth: 200,
    showDelay: 0
  });
  
  //carico il link per la chiamata al REST
  var wordpressUrl ="http://www.mysites.it/sites/wordpress/wp-json/wp/v2/posts";
  $scope.$on('$ionicView.enter', function(){
    console.log('View1 Entered');
     $scope.doRefresh();
  });

  $scope.loadPost = function() {
  // effetuo la chimamata REST API
  $http.get(wordpressUrl)

    // risposta positiva
    .success(function(response,$timeout){
      console.log("Reveived getPosts via HTTP: ", response, status);     
    // Loading Json 
    $ionicLoading.hide();
    $scope.posts = response;
    console.log( response );
    })// fine success

    //risposta negativa
    .error(function(response, status){
      console.log("Error while received response. " + status + response);
    });// fine error

   }// End LoadPost


  // Refresh all'apertura della pagina 
  $scope.doRefresh = function() {
    
    console.log('Refreshing!');
    $timeout( function() {
      //simulate async response
      $scope.loadPost();
      //Stop the ion-refresher from spinning
      $scope.$broadcast('scroll.refreshComplete');
    }, 1000);

  };// Fine Refresh  
      }, false);// end event online 
})// Fine Controller

And what is exactly your problem? The online event is not called or what happened?

If the event is not fired --> add cordova-network-information plugin.

Add corodva network plugin. have a look at this post

remains blocked ionicloading (the charging icon appears) …, but does not get the call