Documentation on Angular Material $mdDialog.finall

2019-07-21 02:10发布

问题:

From the documentation, dialog boxes in Angular Material have a signature like so:

function showAlert() {
  alert = $mdDialog.alert()
    .title('Attention, ' + $scope.userName)
    .content('This is an example of how easy dialogs can be!')
    .ok('Close');
  $mdDialog
      .show( alert )
      .finally(function() {
        alert = undefined;
      });
}

I can't seem to find any documentation on .finally. It appears to be a callback function from what I can gather, though the documentation is oddly lacking any info.

Should I assume it is a normal callback function—and why is the documentation on it lacking—is this simply such standard directive syntax that this is assumed to be the way to deal with callbacks, like .then?

Thanks for any information.

回答1:

$mdDialog.show() returns a promise. finally is an action that you take on completion of a promise, regardless of if it was resolved or rejected. Typically, finally is used to handle whatever cleanup should be done once the promise has completed (just like it does here by clearing the alert variable).

Angular uses the q library to handle promises, so you can find information on the finally() method at the Q API Reference