简体   繁体   中英

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

I am new to the Angular and Node javascript development.

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. 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.

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:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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