Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "dismiss" a modal and "close" a modal in Angular UI-Bootstrap?

What is the difference between "dismiss" a modal and "close" a modal?

close(result) - a method that can be used to close a modal, passing a result dismiss(reason) - a method that can be used to dismiss a modal, passing a reason 
like image 311
Green Avatar asked Nov 02 '13 15:11

Green


People also ask

How do I close a bootstrap modal in angular 8?

Opening & Closing Angular 8 Modal Dialogs open('custom-modal-1') . To close a modal call the modalService. close() method with the id of the modal you want to close, e.g. modalService. close('custom-modal-1') .

How do you make a modal not close on click outside?

Data-keyword="false" is to prevent closing modal while clicking Esc button, while data-backdrop="static" , allows you keep modal pop-up opened when clicking on Gray area.

How do I turn off modal?

We can close the modal pop-up in the following ways:modal('hide'); //Using modal pop-up Id.

How do I turn off modal dialog?

You can simply use the modal('hide') method to hide or close the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('show') and modal('toggle') .


2 Answers

I found that the dismissing of a modal is best to use if it is from a user closing the modal (e.g. returning to the state behind the modal and invoking state.go('^')), and the closing of the modal is used when changing state via $state.go or ui-sref.

That way you can use the result promise to do different things, depending on the what happens.

result.then(function() { /* state change via ui-sref */ })

result.catch(function() { /* user closed modal */ })

like image 38
AnthW Avatar answered Sep 20 '22 22:09

AnthW


The answer is in the documentation, right after the two lines you quoted:

The open method returns a modal instance, an object with the following properties:

  • close(result) - a method that can be used to close a modal, passing a result
  • dismiss(reason) - a method that can be used to dismiss a modal, passing a reason
  • result - a promise that is resolved when a modal is closed and rejected when a modal is dismissed

The important bit here being what happens to the promise. On close, the promise is resolved - essentially, the "success" callback fires. On dismiss, the promise is rejected, therefore running the "failure" callback instead.

like image 177
JB Nizet Avatar answered Sep 22 '22 22:09

JB Nizet