angularjs Material 设计中的对话框弹出窗口如何返回承诺?
How can a promise be returned by a dialog popup in angularjs Material Design?
我正在阅读 Material Design 中 mdDialog 的详细信息,但无法理解为什么弹出警报会 return 一个承诺。 有人可以通过示例解释 mdDialog 是如何 returned 的吗?
Material 设计 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.
它 returns 一个 promise
因为你可能想以不同的方式对未来的事件做出反应,比如 close
(解决承诺)和 cancel
(拒绝它).
mdDialod.show()
returns 一个承诺,如文档中所写,因此您可以解决或拒绝它(如上所述,使用 close
和 cancel
方法$mdDialog
服务)。
Here is a simple example 根据您的要求(打开控制台以查看它如何为每个事件记录相应的文本)。
我觉得文档有点含糊,但这是我如何让它工作的。
在基础控制器中:
$mdDialog.show({/*modalOptions*/})
.then(function(data) {
console.log(data);
}, function(err) {
console.error(err);
}).finally(function() {
// finally block is optional for cleanup
});
在模态控制器中
$scope.cancel = function () {
$mdDialog.cancel('user pressed canceled');
};
$scope.ok = function () {
$mdDialog.hide({message: 'here is some result data'});
};
我正在阅读 Material Design 中 mdDialog 的详细信息,但无法理解为什么弹出警报会 return 一个承诺。 有人可以通过示例解释 mdDialog 是如何 returned 的吗?
Material 设计 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.
它 returns 一个 promise
因为你可能想以不同的方式对未来的事件做出反应,比如 close
(解决承诺)和 cancel
(拒绝它).
mdDialod.show()
returns 一个承诺,如文档中所写,因此您可以解决或拒绝它(如上所述,使用 close
和 cancel
方法$mdDialog
服务)。
Here is a simple example 根据您的要求(打开控制台以查看它如何为每个事件记录相应的文本)。
我觉得文档有点含糊,但这是我如何让它工作的。
在基础控制器中:
$mdDialog.show({/*modalOptions*/})
.then(function(data) {
console.log(data);
}, function(err) {
console.error(err);
}).finally(function() {
// finally block is optional for cleanup
});
在模态控制器中
$scope.cancel = function () {
$mdDialog.cancel('user pressed canceled');
};
$scope.ok = function () {
$mdDialog.hide({message: 'here is some result data'});
};