# Add event listener online

**URL:** <https://forum.ionicframework.com/t/add-event-listener-online/51482>\
**Category:** ionic-v1\
**Created:** [May 8, 2016, 8:10pm UTC](https://forum.ionicframework.com/t/add-event-listener-online/51482 "2016-05-08T20:10:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcnamara](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mcnamara](https://forum.ionicframework.com/u/mcnamara)\
**Post date:** [May 8, 2016, 8:10pm UTC](https://forum.ionicframework.com/t/add-event-listener-online/51482/1 "2016-05-08T20:10:45Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![bengtler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bengtler/32/98565_2.png) [@bengtler](https://forum.ionicframework.com/u/bengtler)\
**Post date:** [May 9, 2016, 5:39am UTC](https://forum.ionicframework.com/t/add-event-listener-online/51482/2 "2016-05-09T05:39:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nitishrajput01](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nitishrajput01/32/123978_2.png) [@nitishrajput01](https://forum.ionicframework.com/u/nitishrajput01)\
**Post date:** [May 9, 2016, 6:26am UTC](https://forum.ionicframework.com/t/add-event-listener-online/51482/3 "2016-05-09T06:26:06Z")

</div>

Add corodva network plugin. have a look at this post

> [@Need help with $rootscope and $cordovaNetwork](https://forum.ionicframework.com/t/need-help-with-rootscope-and-cordovanetwork/44404/6):
>
> check for internet connection if it’s working or not if (navigator.network.connection.type == Connection.NONE) { $ionicPopup.show({ title: '\<h1 class="delete\_popup"\>No Internet Connection !\<br\>', template: '\<h2 class="ceter\_popup\_text"\>You have no Internet Connection\</h2\>', cssClass: 'custom-popup', buttons: [{ text: 'Try Again', …

---

<div class="post-metadata">

**Author:** ![mcnamara](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mcnamara](https://forum.ionicframework.com/u/mcnamara)\
**Post date:** [May 9, 2016, 1:17pm UTC](https://forum.ionicframework.com/t/add-event-listener-online/51482/4 "2016-05-09T13:17:14Z")

</div>

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