Difference between revisions of "Checking online status in AngularJS"

From Wiki2
(Created page with " ==Checking online status in AngularJS== Often apps can do useful work while offline. While online and connected to the server additional functionality is enabled. Knowing if ...")
 
Line 1: Line 1:


==Checking online status in AngularJS==
==Checking online status in AngularJS app==
Often apps can do useful work while offline. While online and connected to the server additional functionality is enabled. Knowing if a device is connected to the internet or if its server is available is the subject of this article.
Often apps can do useful work while offline. While online and connected to the server additional functionality is enabled. It is helpful to know if a device is connected to the internet and if its server is available.
 
You might as well check online status every time your app makes an http request. If you wanted to periodically update your online status you could make a simple http request and intercept its response to set the state of a $rootscope variable that could then be watched by any controllers that needed to.
 
Intercepting http calls, setting some rootScope variables and watching them from a controller, and polling the server periodically to update everything are the steps described below.
 
===Intercepting http calls===
Interceptors are set up in the app.config.
 
 
 
$window.navigator.onLine would tell you if your device is online but not if the server is.
 
===watching rootscape variables===
 
===interval polling of the server===


tags: interceptors, polling, $interval
tags: interceptors, polling, $interval

Revision as of 12:09, 28 August 2014

Checking online status in AngularJS app

Often apps can do useful work while offline. While online and connected to the server additional functionality is enabled. It is helpful to know if a device is connected to the internet and if its server is available.

You might as well check online status every time your app makes an http request. If you wanted to periodically update your online status you could make a simple http request and intercept its response to set the state of a $rootscope variable that could then be watched by any controllers that needed to.

Intercepting http calls, setting some rootScope variables and watching them from a controller, and polling the server periodically to update everything are the steps described below.

Intercepting http calls

Interceptors are set up in the app.config.


$window.navigator.onLine would tell you if your device is online but not if the server is.

watching rootscape variables

interval polling of the server

tags: interceptors, polling, $interval