-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ngMessages leak #16406
ngMessages leak #16406
Conversation
b1896f7
to
48f384f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Always nice when a fix doesn't involve adding more code.
src/ngMessages/messages.js
Outdated
@@ -719,6 +715,10 @@ function ngMessageDirectiveFactory() { | |||
} | |||
} | |||
}); | |||
|
|||
scope.$on('$destroy', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a comment here why this extra listener is necessary.
Btw, is this the new scope that belongs only to the message? Or the parent scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a comment explaining this.
This directive (and the ngMessages
directive) do not create new scopes. So the scope we are listening to is the one that contains this ngMessage
directive. E.g. the scope created by an ngIf
or ngRepeat
directive that wraps this ngMessage
.
'<div ng-if="show"><div ng-message="x">ERROR</div></div>' + | ||
'</div>'; | ||
|
||
element = $compile(html)($rootScope); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be an expectation here that checks that the messge isn't initially attached / in the DOM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
48f384f
to
cc0bdf1
Compare
cc0bdf1
to
b4ecb72
Compare
LGTM. I will merge once Travis has recovered - the builds are currently delayed because of an issue at their end |
…ached Closes angular#16389 Closes angular#16404 Closes angular#16406
Simple Plunker to demo: https://plnkr.co/edit/Ptn5iqTFcpxdu2sGPtFC?p=preview