0

How to get disconnect error message while internet connection is lost via angular & socket.io

Ankur
  • 3
  • 1
  • Welcome to SO! Please post relevant snippet of your code and exact error message. Please see http://stackoverflow.com/help/how-to-ask – xlm Feb 09 '17 at 04:25

1 Answers1

0

You can use navigator function for this. navigator.onLine will return true, if internet is connected otherwise it will return false,

Then bind its value to $rootScope as

$rootScope.online = navigator.onLine

You can use $watch to check it if internet disconnects.

Saurabh Agrawal
  • 7,581
  • 2
  • 27
  • 51
  • If u have the source code for this task. could u please share with us. so i can match easily. still not done – Ankur Feb 09 '17 at 05:04
  • @Ankur try this link http://stackoverflow.com/questions/24121369/how-to-check-user-has-internet-connection-using-angularjs And accept my answer if it works :) – Saurabh Agrawal Feb 09 '17 at 05:22
  • Please check this scrip is this ok.... window.addEventListener('load', function() { var status = document.getElementById("status"); var log = document.getElementById("log"); function updateOnlineStatus(event) { var condition = navigator.onLine ? "online" : "offline"; status.className = condition; status.innerHTML = condition.toUpperCase(); log.insertAdjacentHTML("beforeend", "Event: " + event.type + "; Status: " + condition); } window.addEventListener('online', updateOnlineStatus); window.addEventListener('offline', updateOnlineStatus); }); – Ankur Feb 09 '17 at 08:15