-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Dialog does not destroy scope/watchers on close #232
Dialog does not destroy scope/watchers on close #232
Conversation
Good catch @anton-dev-ua . In fact we need to still tweak dialog a bit to make it perfect. The reason of the current behavior is that |
I realised that scope cannot be simply destroyed as it can come from locals (from resolve). But even if scope is passed into the dialog, it creates new watchers in the scope every time. I created one more plunker to demonstrate this: http://plnkr.co/edit/nwbzD4?p=preview So in case of incoming scope, only watchers should be destroyed. Maybe somthing like this: Dialog.prototype._onCloseComplete = function(result) {
...
if(this.scopeFromLocals){
this.$scope.$$watchers = [];
}else{
this.$scope.$destroy();
}
}; Sorry, if I say obvious things, I am new to angularJS and angularUI, but already love them and want them to be perfect :) |
@anton-dev-ua I really appreciate you looking into this! You are right in your analysis, pretty amazing for a person just starting with AngularJS! Now, for the problem at hand - it is a bit more complex than this - in fact we should be destroying scopes only if we create them. The fact that the Would love to fix this asap but won't be able to work on this topic for a couple of next days. @SidhNor would you mind giving a hand to @anton-dev-ua ? |
What you really need here is to always create a new scope. Then you are free to delete it when you are done with it. This is how scopes are designed to work. So on line https://github.com/angular-ui/bootstrap/blob/master/src/dialog/dialog.js#L119, we should be doing something like:
Notice that if locals has a scope then we replace it with a child scope: locals.$scope.$new(). Then you can safely call self.$scope.$destroy() in the onClose handler. |
I have implemented suggestion of @petebacondarwin. I only didn't get why we should copy locals as they are created every time dialog is opening. |
Hi @anton-dev-ua , Gleb |
Hi @SidhNor , |
+1 having this same issue with $watch's |
@anton-dev-ua - I guess I was just being safe since this function is modifying the passed in locals object, I didn't want to have any unwanted side-effects. But if you are sure that locals is always generated freshly each time then it is safe just to use the reference. |
I am not familiar with the code enough, of course, but as I can see locals come from promise returned by _loadResolves(): https://github.com/angular-ui/bootstrap/blob/master/src/dialog/dialog.js#L118 Btw, looks like angular can't copy locals, at least I got error in tests when tried to do this:
|
This works for me |
It will be handled in #441 |
This issue is still not solved (Version 0.5.0). I've updated the plnkr from anton_dev_ua: http://plnkr.co/edit/5EuMfH?p=preview With the modifications from stevebacondarwin and anton-dev-ua it is working as expected. |
@kwehrle The fix (in fact - complete rewrite) will be only part of 0.6.0 so it is normal that it is not fixed in 0.5.0. We should release 0.6.0 over the weekend. |
Hi
I found next issue in a dialog module.
When dialog is opening it creates new scope. But it does not destroy this scope when it is closing. So amount of scopes (and watchers, etc.) increases with every reopening of the dialog.
I created the Plunker to illustrate the issue: http://plnkr.co/edit/sPhpu9?p=preview
I think adding something like this.$scope.$destroy() at the end of _onCloseComplete() can resolve the issue, if I don't miss something:
Thanks
Regards,
Anton