I am using $mdDialog service of AngularMaterial. Here's the sample code that I am using -
var highlighter = {};
$mdDialog.show({
templateUrl: 'sample.html',
parent: angular.element(document.body),
clickOutsideToClose: true,
bindToController: true,
onRemoving: function (event, removePromise) {
if(highlighter.answer!==1) {
//Do something here
}
highlighter.answer = undefined;
}
})
.then(function (answer) {
highlighter.answer = answer;
});
the promise which is returned by show()
method resolves only when any of the buttons in mdDialog are clicked. The index of the buttons is provided as answer
parameter. I need to do something only when the answer/button index is not equal to 1.
The problem is onRemoving gets called before resolving the promise when any of the buttons is clicked, so the highlighter.answer
didn't get the proper value when it's needed (In onRemoving callback).
In other words, onRemoving gets called whenever any of the buttons is called or when the dialog is dismissed without clicking the buttons. the promise gets resolved only when the button is clicked.
So my question is, is there any way to have any callback which will get called after the promise is resolved (then is called), so that the answer value is set and I know whether a button is called or not. This callback should get called on removing the dialog whether the promise is resolved or not.