Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

WIP fix(ngMessages): fix orphaned ng-message comments when using ng-if #16404

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/ngMessages/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,14 @@ function ngMessageDirectiveFactory() {
require: '^^ngMessages',
link: function(scope, element, attrs, ngMessagesCtrl, $transclude) {
var commentNode = element[0];
element.scope().$on('$destroy', function() {
// in the event that the element or a parent element is destroyed
// by another structural directive then it's time
// to deregister the message from the controller
// we do this here instead of in the attach function because otherwise
// comments that are not rendered will not be cleaned up
ngMessagesCtrl.deregister(commentNode);
});

var records;
var staticExp = attrs.ngMessage || attrs.when;
Expand Down Expand Up @@ -696,12 +704,8 @@ function ngMessageDirectiveFactory() {
// when we are destroying the node later.
var $$attachId = currentElement.$$attachId = ngMessagesCtrl.getAttachId();

// in the event that the element or a parent element is destroyed
// by another structural directive then it's time
// to deregister the message from the controller
currentElement.on('$destroy', function() {
if (currentElement && currentElement.$$attachId === $$attachId) {
ngMessagesCtrl.deregister(commentNode);
messageCtrl.detach();
}
newScope.$destroy();
Expand Down