我正在阅读Material Design中有关mdDialog的详细信息,并且无法理解为什么警报弹出窗口会返回一个promise.有人可以通过一个例子来解释mdDialog如何返回一个promise吗?
Material Design mdDialog的文档说明如下:
$mdDialog opens a dialog over the app to inform users about critical information or require them to make decisions. There are two approaches for setup: a simple promise API and regular object Syntax.
解决方法
它返回一个promise,因为你可能希望以不同的方式对未来事件做出反应,比如close(解析promise)和取消(拒绝它).
mdDialod.show()返回一个promise,如文档中所述,因此您可以解析或拒绝它(如上所述,在$mdDialog服务上使用close和cancel方法).
您请求的Here is a simple example(打开控制台以查看它如何记录每个事件的相应文本).