title: addEventListener for "offline" firing multiple times in ionic
body: <p>For some reason, When the application goes into offline mode the event listener is firing multiple times and how to make it fire only once.</p>
  
  <pre><code>  $rootScope.$on('$ionicView.afterEnter', function (event, view) {
  
      $rootScope.online = navigator.onLine;
      var popup;
  
      $window.addEventListener("offline", function () {
        $rootScope.$apply(function () {
          $rootScope.online = false;
          popup = $ionicPopup.confirm({
            title: 'Network Problem',
            content: 'Sorry, Please Check Your Network Connection.'
          })
        });
      }, false);
      $window.addEventListener("online", function () {
        $rootScope.$apply(function () {
          $ionicLoading.show({
            template: '&lt;p&gt;Loading...&lt;/p&gt;&lt;ion-spinner&gt;&lt;/ion-spinner&gt;',
          });
          $rootScope.online = true;
          $state.reload();
    }, false);
  });
  </code></pre>