Check for internet connection on the device

I’m checking whether there are any petition AJAX or HTTP within my app, and it works perfect, now I want to do the same but verifying whether or not internet connection on the phone to before displaying, display a gif loader on the splashscreen ? is this possible?



Use ng-cordova!

1 Like

If you choose not to use ngCordova you could also check for an internet connection like below:

ngCordova is the best route now though.

1 Like

thanks for the info now I doubt remains. As I can assess Internet connection before the splash screen? I still unclear after.

1 Like

In android I works really well, but in iOS at all, in fact just checked that my control does not work on ajax.

.config(function ($httpProvider) {
    var spinnerFunction = function (data, headersGetter) {
        // todo start the spinner here
        //alert('start spinner');
        return data;
 // register the interceptor as a service, intercepts ALL angular ajax http calls
.factory('myHttpInterceptor', function ($q, $window) {
    return function (promise) {
        return promise.then(function (response) {
            // do something on success
            // todo hide the spinner
            //alert('stop spinner');
            return response;

        }, function (response) {
            // do something on error
            // todo hide the spinner
            //alert('stop spinner');
            return $q.reject(response);

You have two ways to check internet

by connection object - install
ngCordova plugin - install ngCordova for your project.

check this url can be useful.