m-e-conroy / angular-dialog-service

A complete AngularJS service with controllers and templates for generating application modals and dialogs for use with Angular-UI-Bootstrap and Twitter Bootstrap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

check if dialog is open using isOpen

programming-kid opened this issue · comments

there should be a function to check if particular dialog is open like isOpen using a dialog name or id specified while creating dialog

I've been using this code base since it's creation and haven't had a use case for this. Not saying this isn't a valid request but what behavior are you running into that you need this?

i have a login modal which is fired on 401 response so every time user enters wrong credentials another modal is opened so i need isOpen to check if login modal is already open

So, that's something you can track on your own though - the library provides a promise when it is opened. It can be as simple as having a service, or even just a simple run that keeps a local variable (isDialogOpened) and then only opens it if it is not already opened, etc.

yea i know it can be done but its not an elegant solution , i just wanted a clean solution

I was looking for the same thing, a way to find open dialogs so we don't need to open another instance if one is already open. My use case is the UI is frequently pinging the REST API to see if it's available. If there is a disconnection, an alert dialog is displayed saying the server is unavailable. We want it to keep pinging though, so the UI will wake back up when the server is back online. The problem I'm having is it's creating an infinite number of dialogs with the same message, so I'd like to determine first whether there is already an open dialog. I would rather not have to hook in every time a user closes a dialog to find when I need to update some flag regarding whether the dialog is open.

You can still track all this in your own service; have your 'offline' or 'connection problem' code/error handler emit an event, and have another piece that listens to those events and raises the dialog. In that place it's as simple as if () ... with a local var.