简体   繁体   English

节点服务器停止后可以调用$ modal.open吗

[英]Can I call a $modal.open after node server is stopped

I am new to the Angular and Node javascript development. 我是Angular和Node javascript开发的新手。

My question is if i stop the Node server I want to show a warning message to the user and direct the user to the login screen, so can i call $modal.open to show a modal view page and on user confirmation redirect the user to login screen and close out the session. 我的问题是我是否要停止向节点服务器显示警告消息并将用户定向到登录屏幕,所以我可以调用$ modal.open来显示模式视图页面,并在用户确认时将用户重定向至登录屏幕并关闭会话。 My apologies if this is a stupid question. 如果这是一个愚蠢的问题,我表示歉意。

Thank you. 谢谢。

Once an Angular page has been loaded in the browser, the node server is irrelevant unless you start making Ajax calls -- the clientside angular code will happily keep on running clientside for as long as the user keeps the browser window open. 一旦在浏览器中加载了Angular页面,节点服务器就无关紧要,除非您开始进行Ajax调用-只要用户保持浏览器窗口打开,客户端的Angular代码就会愉快地保持在客户端运行。

If your goal is to detect that the server has stopped responding to XHR requests (for whatever reason) and show a modal in response, you can certainly do that -- the following config block for example would globally catch any server error and let you Do Stuff as needed: 如果您的目标是检测服务器已停止响应XHR请求(无论出于何种原因)并显示响应模式,则可以这样做-例如,以下配置块将全局捕获任何服务器错误,并让您执行所需的东西:

.config(function ($httpProvider) {
    $httpProvider.interceptors.push(function ($q) {
        return {
            'responseError': function (err) {
                // Do Stuff Here.
                // (More realistically you'd want to inspect the contents of the
                // 'err' variable to determine what type of error you're 
                // dealing with, and decide which Stuff to Do based on that)
                return $q.reject(err); // pass the rejection on to any downstream promise handlers
            }
        };
    });
});

(More detail here: https://docs.angularjs.org/api/ng/service/ $http ) (更多详细信息在这里: https : //docs.angularjs.org/api/ng/service/ $ http)

Whether you can use that to redirect to a login screen and let the user clear their session depends on how you're serving out that login screen, and how you're clearing out sessions -- if all of those are purely clientside operations in your setup, it'll work fine; 是否可以使用它重定向到登录屏幕并让用户清除会话,取决于您如何为该登录屏幕提供服务,以及如何清除会话-如果所有这些纯粹是您的客户端操作设置,它将正常工作; if any depend on the server which you've stopped, then presumably it won't work fine. 如果有任何依赖于您已停止的服务器,则大概无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM