E
E
Egor2015-02-12 20:14:11
JavaScript
Egor, 2015-02-12 20:14:11

How to implement your analogue of confirm in angular?

Greetings.
I need a dialog that works similar to calling confirm. That is, a dialog appears and code execution stops until a result is returned.
I tried using an infinite loop,

var confirmResult = -1;
$rootScope.$emit('showConfirmDialog','Are you sure?');
var deregFunc = $rootScope.$on('confirmDialogResult',function(e,result){
    //сообщение от диалога после клика на кнопку.
     confirmResult = result;
});

 while(confirmResult === -1){
 }

 alert(confirmResult);
 deregFunc();

but because of this, the whole application freezes and it is impossible to click on the button in the dialog. Tell me how to implement this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kartio, 2015-02-12
@kartio

does it make sense to do so?
you can also call the desired function in the confirmation handler (in extreme cases, emit another event), and block all input fields through an overlay above the document

S
Sergey, 2015-02-12
Protko @Fesor

You make a service, everything else is in it. As for "stop everything and everyone" - it depends on what exactly you want to stop. Usually it is enough to add an overlay to prevent user actions, and you can also add a request interceptor that will wedged into the promise chain and suspend all requests for the time you need.
And yes, an infinite loop is brilliant ... You have everything running in one thread, and js, and rendering and processing user input and actions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question