在离子框架中显示连接错误消息 [英] display connection error messages in ionic framework

查看:101
本文介绍了在离子框架中显示连接错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发离子移动应用程序,但很难显示连接错误消息。当设备未连接到互联网或连接超时或其他什么时,我想显示弹出窗口以显示错误消息。这是我第一次遇到这样的事情。

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 connection timeout or something then I want to show a popup to display the error message. This is my first time encountering something like this.

推荐答案

- 首先将插件添加到你的项目
然后进入您的app.js包含以下代码

--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);

此处offile将处理连接终止,在线将处理重新连接并检查警报或控制台

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

这篇关于在离子框架中显示连接错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆