mdDialog:捕获onClose事件 [英] mdDialog: catch the onClose event
问题描述
我正在创建一个有角度的邮箱.而且,当发送消息的弹出窗口关闭时,我需要保存消息草稿.
I'm creating a mailbox in angular. And I would need to save the draft message when the popup to send a message closes.
我知道还有其他选择:
scope.$on("$destroy", function () { saveMessage() });
和:
$mdDialog.show(...).finaly(function(){ saveMessage() });
但两者都不足够:
- 在对话框已关闭时调用第一个.这是由于要求不可接受(有一个iFrame需要打开)
- 第二个控件不在mdDialog控制器的范围之内,它负责弹出窗口的调用者,而它应该在弹出窗口本身中.
因此,我正在寻找一种在弹出窗口实际关闭之前调用函数的方法.
类似于scope.$on("$mdDialogBeforeClose", function () { saveMessage() });
So I'm looking for way to call a function BEFORE the pop-up actually closes.
Something like scope.$on("$mdDialogBeforeClose", function () { saveMessage() });
另一个选择是挂接每个close事件.看起来很丑,但可能是解决方案.在那种情况下,我将需要监听转义按钮并在弹出窗口之外单击(虽然我可能会禁用该功能)...
Another option would be to hook every close event. Seems ugly, but might be the solution. In that case I would need to listen to the escape-button and clicking outside the pop-up (Altough I might disable that function)...
还有更好的主意吗?
谢谢!
编辑:
另一个问题:如何捕获转义按键事件?我尝试了<md-dialog aria-label="List dialog" ng-keypress="keyPress($event)">
,但它甚至没有被触发...
An addition question: How to catch the escape-keypress event? I tried <md-dialog aria-label="List dialog" ng-keypress="keyPress($event)">
but it's not even triggered...
推荐答案
也许使用onRemoving
回调-从文档中
标记
<div ng-controller="MyController as vm" id="popupContainer" ng-cloak="" ng-app="app">
<md-button class="md-primary md-raised" ng-click="vm.open($event)">
Custom Dialog
</md-button>
<script type="text/ng-template" id="test.html">
<md-dialog aria-label="Test">
Hello!
</md-dialog>
</script>
</div>
JS
angular.module('app',['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('MyController', function($scope, $mdDialog) {
this.open = function(ev) {
$mdDialog.show(
{
templateUrl: "test.html",
clickOutsideToClose: true,
onRemoving: function (event, removePromise) {
console.log(123);
}
});
};
})
这篇关于mdDialog:捕获onClose事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!