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
    content: 'Loading',
    animation: 'fade-in',
    showBackdrop: true,
    maxWidth: 200,
    showDelay: 0
  //carico il link per la chiamata al REST
  var wordpressUrl ="";
  $scope.$on('$ionicView.enter', function(){
    console.log('View1 Entered');

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

    // risposta positiva
      console.log("Reveived getPosts via HTTP: ", response, status);     
    // Loading Json 
    $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() {
    $timeout( function() {
      //simulate async response
      //Stop the ion-refresher from spinning
    }, 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