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

ngMessages with bound message doesn't remove watch when message is removed #14307

Closed
jwalker-scottlogic opened this issue Mar 23, 2016 · 2 comments · Fixed by #14308
Closed

Comments

@jwalker-scottlogic
Copy link

We have ngMessage texts which can change, and so are bound to model values rather than being hardcoded into the view.

eg.

<div ng-messages="form.input.$error">
    <div ng-message="myError">{{errorMsg}}</div>
</div>

Every time the message is shown, it adds a new watch which is not removed when the message is removed, but stays added until the parent ng-messages element is destroyed.

JSFiddle showing the problem is available here https://jsfiddle.net/jwalkersl/Lumjd9tm/

@Narretz Narretz self-assigned this Mar 23, 2016
@Narretz Narretz added this to the Backlog milestone Mar 23, 2016
@Narretz
Copy link
Contributor

Narretz commented Mar 23, 2016

That's quite a leak there ... not sure if there's an easy way to fix it. Does your message text change while it is displayed? If not, as a workround you could use one-time bindings, so no watcher is added at all.

@jwalker-scottlogic
Copy link
Author

Yes, we have some messages which need to update while they're displayed - others already use one-time bindings where we can.

Narretz added a commit to Narretz/angular.js that referenced this issue Mar 23, 2016
Previously, ngMessage elements used the same scope as ngMessages. When ngMessage
has interpolation in the textContent, then removing the message would not remove
the watcher from the scope - it would only be removed when the whole ngMessages
element was removed.

This commit changes the ngMessage transclude function to create a new child scope
instead, which can be destroyed safely when the message element is removed and
the message is detached

Fixes angular#14307
Narretz added a commit to Narretz/angular.js that referenced this issue Mar 24, 2016
Previously, ngMessage elements used the same scope as ngMessages. When ngMessage
has interpolation in the textContent, then removing the message would not remove
the watcher from the scope - it would only be removed when the whole ngMessages
element was removed.

This commit changes the ngMessage transclude function to create a new child scope
instead, which can be destroyed safely when the message element is removed and
the message is detached

Fixes angular#14307
Narretz added a commit to Narretz/angular.js that referenced this issue Jun 10, 2016
Previously, ngMessage elements used the same scope as ngMessages. When ngMessage
has interpolation in the textContent, then removing the message would not remove
the watcher from the scope - it would only be removed when the whole ngMessages
element was removed.

This commit changes the ngMessage transclude function to create a new child scope
instead, which can be destroyed safely when the message element is removed and
the message is detached

Fixes angular#14307
Narretz added a commit that referenced this issue Jun 10, 2016
Previously, ngMessage elements used the same scope as ngMessages. When ngMessage
has interpolation in the textContent, then removing the message would not remove
the watcher from the scope - it would only be removed when the whole ngMessages
element was removed.

This commit changes the ngMessage transclude function to create a new child scope
instead, which can be destroyed safely when the message element is removed and
the message is detached

Fixes #14307
PR (#14308)
Narretz added a commit that referenced this issue Jun 10, 2016
Previously, ngMessage elements used the same scope as ngMessages. When ngMessage
has interpolation in the textContent, then removing the message would not remove
the watcher from the scope - it would only be removed when the whole ngMessages
element was removed.

This commit changes the ngMessage transclude function to create a new child scope
instead, which can be destroyed safely when the message element is removed and
the message is detached

Fixes #14307
PR (#14308)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants