display connection error messages in ionic framework

前端 未结 1 996
情深已故
情深已故 2021-01-28 04:23

I am developing an ionic mobile app but getting difficulty to display the connection error message. When the device is not connected to the internet or when there is a connectio

1条回答
  •  臣服心动
    2021-01-28 05:09

    --first add the plugin to your project then in your app.js include the below code

    js

    document.addEventListener("offline", onOffline, false);
    
            $rootScope.online = true;
            function onOffline() {
                // Handle the offline event
                $rootScope.$apply(function() {
                    $rootScope.online = false;
                   alert("There is no active internet connection to your app. Please check the connectivity.");
                   //implement your method off error when the connection terminates
    
                });
             }
    
            document.addEventListener("online", function() {
                $rootScope.$apply(function() {
    alert("connected");
                    $rootScope.online = true;
                    $rootScope.closeToast();
                });
            }, false);
    

    here offile will handle the connection termination and online will handle the reconnection and check with the alerts or consoles

    0 讨论(0)
提交回复
热议问题