What is the difference between “firing” a modal and a “closed” modal in Angular UI-Bootstrap?

What is the difference between the "dismissal" of the modal and the "closed" 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 
+62
angularjs angular-ui angular-ui-bootstrap
Nov 02 '13 at 15:07
source share
2 answers

The answer is given in the documentation immediately after the two lines that you indicated:

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

  • close (result) - a method that can be used to close a modal file, passing the result
  • dismissal (reason) - a method that can be used to reject a modal code, transfer reasons
  • The result is a promise that is resolved when the modal object is closed and rejected when the modal is rejected.

The important thing here is what happens to the promise. Upon completion, the promise is resolved - essentially the success callback is triggered. Upon dismissal, the promise is rejected, so the failure callback is instead executed.

+67
Nov 02 '13 at 15:25
source share

I found that modality rejection is best used if it belongs to the user closing the modal (for example, returning to the state behind the modal and calling state.go ('^')), and modal closing is used when changing state through $ state.go or ui-sref.

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

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

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

+1
Apr 24 '17 at 14:18
source share



All Articles