mdDialog: $mdDialog.show() promise rejecting when using option callbacks w/ element
Actual behavior:
- What is the issue? When trying to add or remove a class from
elementinonShowing,onComplete, oronRemoving, the$mdDialog.show()promise is rejected. - What is the expected behavior? The promise should resolve per usual, rather than rejecting.
CodePen or Steps to reproduce the issue: *
- CodePen Demo which shows your issue: http://codepen.io/anon/pen/XKMJNj?editors=1010
- Details: Need to be able to track whether the dialog is in its entering or exiting animations, so I wanted to manually add and remove the
ng-animatecss class. However, this causes theshow()promise to always reject when either of the dialog buttons are pressed. Removing theelement.addClassandelement.removeClassfrom the callback functions causes the dialog to resolve per usual.
Angular Versions: *
- Angular Version: 1.5.5
- Angular Material Version: 1.1.0-rc.5
Additional Information:
- Browser Type: Chrome Canary
- Browser Version: 53.0.2777.0 canary (64-bit)
- OS: Mac OSX 10.10.5
- Stack Traces:
Shortcut to create a new CodePen Demo.
Note: * indicates required information. Without this information, your issue may be auto-closed.
Do not modify the titles or questions. Simply add your responses to the ends of the questions. Add more lines if needed.
This doesn't even work if you remove the callbacks. This seems to be an issue with your dialog template / setup.
@DevVersion
Here's the demo with the element stuff removed: http://codepen.io/anon/pen/MepYZb?editors=1010
The dialog opens, console spits out 'adding ng-animate' and 'removing ng-animate'. Clicking Useful / Not useful shows that respective text in the result output, and console shows 'adding ng-animate'. So I think it's working properly in this case?
@zlovin Seems like I can reproduce your issue now. I'll try to take a look at it.
So I investigated at your codepen.
You're not using the callbacks correctly
onShowing(scope, element) {}
onComplete(scope, element) {}
onRemoving(element, actionPromise) {}
The onRemoving function is not able to pass a scope, so it's just the element and the given action promise.
@DevVersion Okay, then the documentation on the material page needs to be updated to reflect that. Only saw the documentation for onComplete in the docs for $mdDialog and it said function afterShowAnimation(scope, element, options), which doesn't match what you mention (also, onShowing is missing the paired backtick in the docs).
I also tried updating my original codepen with what you said, but I'm still having a bit of trouble. Does the onRemoving need to return the promise, or reject or resolve it? I tried returning the promise, resolving the promise, and resolving and returning it. It still rejected in every case. Updated demo.
If the promise does need to be resolved in the onRemoving callback, then couldn't that get nasty because the callback couldn't know the circumstances of the dialog? Leads me to think that it doesn't need to be resolved, but then I don't know what / if I need to return to get the dialog to properly resolve. Have any advice?
Edit: Related, could the animation css classes be added to dialogs? I was surprised that they weren't there in the first place, but maybe that's because they don't leverage ngAnimate. Haven't done much with animations and angular material, so I don't know if this is the case for most elements or not.
@zlovin No that promise is just there to track the removing process. (If the transition has finished etc.)
Actually your demo is not working because you have a little typo in the parameter, which throws a RTE.
// Notice the `elememt` here.
$scope.onRemoving = function(elememt, actionPromise) {
I've updated your demo to fix that typo and it works as expected. See here
@DevVersion D'oh, nice catch. Thanks for the help!