-
Notifications
You must be signed in to change notification settings - Fork 27.5k
JQLite.find() fails on when collection contains text nodes #4120
Comments
@hsablonniere - So if your transcluded contents contain top level text nodes then the
What happens if you use jQuery instead of jqLite? |
Exactly. It's even more tricky because line feed and carriage return create text nodes. So it's invisible. I guess it would work with jQuery since it does a Maybe I'm not using this stuff correctly but if it's not the case there's two possible fixes :
What do you think ? |
I guess that |
Yeah thanks very much. I actually needed to find a node by tag name amongst the items of the JQLite array and I've done it by hand using vanilla DOM. Do you want me to work on a PR ? Either modify the JQLite.find() or the cloneLinkingFn argument... |
@hsablonniere - I think the fix would be on |
Ok thx. |
I'm not totally sure I understand what the "bug" is --- I've spent some time trying to build a plnkr to reproduce the issue, and I'm not actually seeing text nodes being forgotten to be cloned. Text nodes are not able to be branch nodes, they are always leafs, and so it's not like there can be content nested within them which is forgotten. I'm not saying that this isn't a bug, but it would be good to provide a plnkr so that it's more clear what is actually happening, and so that it's clear what the bug really is. Just a thought. |
You're absolutely right. I'll provide one this weekend ;-) |
Here's a very silly example demonstrating the bug : With jQuery : http://plnkr.co/edit/WYO9DJ Error in console :
|
The bug is, in that calling |
find check if the element is a text node. If element is a text node return an empty array. Otherwise invoke getElementsByTagName on the element and return the result Closes angular#4120
When a jqLite collection contains text nodes, find() does not work :-( This fix ignores all nodes than can't do getElementsByTagName() It seems a little bit faster than testing nodeType : http://jsperf.com/nodetype-vs-duck-typing Closes angular#4120
When a jqLite collection contains text nodes, find() does not work :-( This fix ignores all nodes than can't do getElementsByTagName() It seems a little bit faster than testing nodeType : http://jsperf.com/nodetype-vs-duck-typing Closes angular#4120
I created a directive. I use the transclude function passed by compile to clone one element of the original DOM into my template DOM.
clone
is a JQLite array-like object and when you callfind(tagName)
on it, it callsfind(tagName)
on each element and group the results. The problem is thatclone
can contain text nodes and behind the scenes,find(tagName)
usesgetElementsByTagName
which doesn't work on text nodes.The text was updated successfully, but these errors were encountered: