-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(ngMessages): ensure that multi-level transclusion works with ngMessagesInclude #11199
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,27 +500,21 @@ angular.module('ngMessages', []) | |
|
||
return { | ||
restrict: 'AE', | ||
require: '^^ngMessages', | ||
compile: function(element, attrs) { | ||
var comment = jqLite($document[0].createComment(' ngMessagesInclude: ')); | ||
element.after(comment); | ||
|
||
return function($scope, $element, attrs, ngMessagesCtrl) { | ||
// we're removing this since we only need access to the newly | ||
// created comment node as an anchor. | ||
element.remove(); | ||
|
||
$templateRequest(attrs.ngMessagesInclude || attrs.src).then(function(html) { | ||
var elements = jqLite('<div></div>').html(html).contents(); | ||
var cursor = comment; | ||
forEach(elements, function(elm) { | ||
elm = jqLite(elm); | ||
cursor.after(elm); | ||
cursor = elm; | ||
}); | ||
$compile(elements)($scope); | ||
require: '^^ngMessages', // we only require this for validation sake | ||
link: function($scope, element, attrs) { | ||
var src = attrs.ngMessagesInclude || attrs.src; | ||
$templateRequest(src).then(function(html) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. making this directive an element transclusion directive makes it unnecessary to add this manually (making it terminal would avoid worrying about compiling nested gunk) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we set terminal to true then will this run last if the priority is left unset? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. directives are evaluated in the deterministic order, but they'll stop when they reach the terminal one. similarly, child nodes of an element with a terminal directive won't be compiled (but there are no children, except the ones you load from the server and compile on your own.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I know how this works, but please answer my question if it will be handled last if a priority is not assigned in the directive definition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it will. the default priority is 0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR has been updated with a new commit. I don't think we should set this to terminal since it is already working. |
||
$compile(html)($scope, function(contents) { | ||
element.after(contents); | ||
|
||
// the anchor is placed for debugging purposes | ||
var anchor = jqLite($document[0].createComment(' ngMessagesInclude: ' + src + ' ')); | ||
element.after(anchor); | ||
|
||
// we don't want to pollute the DOM anymore by keeping an empty directive element | ||
element.remove(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for removing all this though, it's more complicated than is really needed |
||
}; | ||
}); | ||
} | ||
}; | ||
}]) | ||
|
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.
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?)
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.
All fixed up now. And I added some comments to the unit test.