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

fix(ngMessages): ensure that multi-level transclusion works with ngMessagesInclude #11199

Closed
wants to merge 1 commit into from

Conversation

matsko
Copy link
Contributor

@matsko matsko commented Feb 26, 2015

ngRepeat and any other directives that alter the DOM structure using
transclusion may cause ngMessagesInclude to behave in an unpredictable
manner. This fix ensures that the element containing the ngMessagesInclude
directive will stay in the DOM to avoid these issues.

Closes #11196

link: function($scope, element, attrs) {
$templateRequest(attrs.ngMessagesInclude || attrs.src).then(function(html) {
element.html(html);
$compile(element.contents())($scope);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the best approach. Why not just make use of the clone attach feature of the link function?

$templateRequest(attrs.ngMessagesInclude || attrs.src).then(function(html) {
  $compile(html)($scope, function(dom) {
    // attach to DOM using your favourite method --- finding the parent ngMessages directive will no longer fail.
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit to having this code be inserted in a different way? There's no animation stuff here since that's managed in the <ng-message> directive level which transcludes on its own anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the benefit is not adding a breaking change --- keeping the DOM looking the way it did before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works amazing! Thanks! You just saved a very inconvenient breaking change.

@matsko matsko changed the title fix(ngMessages): ensure that the ngMessagesInclude element is persisted in the DOM fix(ngMessages): ensure that multi-level transclusion works with ngMessageInclude Feb 27, 2015
@matsko matsko changed the title fix(ngMessages): ensure that multi-level transclusion works with ngMessageInclude fix(ngMessages): ensure that multi-level transclusion works with ngMessagesInclude Feb 27, 2015
@caitp
Copy link
Contributor

caitp commented Feb 27, 2015

LGTM, but I would suggest adding some comments explaining the flow and assertions in that large unit test.

cursor = elm;
});
$compile(elements)($scope);
require: '^^ngMessages', // we only require this for validation sake
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, hang on. Previously, you were basically replacing the element with a comment placeholder. I think we should keep doing this, there's no good reason to keep it in the DOM (is there?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All fixed up now. And I added some comments to the unit test.

…ssagesInclude

ngRepeat and any other directives that alter the DOM structure using
transclusion may cause ngMessagesInclude to behave in an unpredictable
manner. This fix ensures that the element containing the ngMessagesInclude
directive will stay in the DOM to avoid these issues.

Closes angular#11196
@caitp
Copy link
Contributor

caitp commented Feb 27, 2015

thanks, lgtm.

@matsko
Copy link
Contributor Author

matsko commented Feb 27, 2015

Merged as d7ec5f3

@matsko matsko closed this Feb 27, 2015
@matsko
Copy link
Contributor Author

matsko commented Feb 27, 2015

Thanks @caitp

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(ngMessages): ngMessagesInclude crashes inside ngRepeat
3 participants