You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
If the docs are correct, this code should throw an error, as the top level node doesn't have a parent node. But instead the console output is:
Second Level => Second Level
First Level => First Level
The Angular code
This is the Angular code (jqLite):
function jqLiteInheritedData(element, name, value) {
// if element is the document object work with the html element instead
// this makes $(document).scope() possible
if(element.nodeType == 9) {
element = element.documentElement;
}
var names = isArray(name) ? name : [name];
while (element) {
for (var i = 0, ii = names.length; i < ii; i++) {
if ((value = jqLite.data(element, names[i])) !== undefined) return value;
}
// If dealing with a document fragment node with a host element, and no parent, use the host
// element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
// to lookup parent controllers.
element = element.parentNode || (element.nodeType === 11 && element.host);
}
}
And you can see that the InheritedData search starts on the current element, not on the parent.
Hopefully a bug
So either the docs are wrong, or the code is wrong.
I'm not sure why the search starts on the current element, or what will be the consequences of changing it to start on the parent. But I've already been involved with 3 directives that could benefit from '^' search starting on the parent, as often you wish to have an hierarchy of the same directive.