关于 Angular Material $mdDialog.finally 的文档? [英] Documentation on Angular Material $mdDialog.finally?

查看:21
本文介绍了关于 Angular Material $mdDialog.finally 的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档,对话框Angular Material 有这样的签名:

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;
      });
}

我似乎找不到关于 .finally 的任何文档.从我收集到的信息来看,它似乎是一个回调函数,尽管文档奇怪地缺少任何信息.

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.

我是否应该假设它是一个普通的回调函数——为什么缺乏关于它的文档——这只是这样的标准指令语法,它被认为是处理回调的方式,比如 .then?

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?

感谢您提供任何信息.

推荐答案

$mdDialog.show() 返回一个 promise.finally 是你在完成承诺时采取的行动,无论它是被解决还是被拒绝.通常,finally 用于处理承诺完成后应执行的任何清理工作(就像这里通过清除 alert 变量所做的那样).

$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 使用 q 库来处理 Promise,因此您可以在 Q API 参考

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

这篇关于关于 Angular Material $mdDialog.finally 的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆