-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix($compile): properly handle directive replace for table elements #3647
Conversation
To work around limitations in jqLite, the template snippet is wrapped in a <div> element. This does not work for table elements, since they cannot be constructed inside a div. This patch takes special to properly wrap caption, thead, tbody, tfoot, tr, th and td in tags that allow them to be created. Closes #1459
+1 |
2 similar comments
+1 |
+1 |
+1 |
1 similar comment
+1 |
I've recklessly started learning directives from writing the one for table manipularing, and had no idea what was doing wrong until found out things work properly when I replace tr/ths with divs or anything else. |
If this works in jQuery, perhaps it would be better to improve jqLite. @IgorMinar what do you think of this? |
This is more of a browser thing, It might be possible to do away with the div-wrapping altogether by improving jqLite, though. |
@pelme why would one need to wrap table-only element with div? |
Punting this to |
Is there any workaround/dirty fix for that? Or should we just avoid table-related directives until 1.2.1 ? |
the problem here is that angular needs to create fragments of dom and the easiest way to do so is via innerHTML. with innerHTML howerver, you need a container to innerHTML the string template into and we use Even if we did, there is still issue with multi-root templates |
Summing up, will this one be kind of wontfix answer? I have seen quite a few table related directives and all of them uses some tricks for overcoming this problem. |
Btw, @IgorMinar if auto-detecting what wrapping tag should be used, how about letting the developer decide? Just add the "templateWrapper" property which defaults to ' ', yet the developer could provide other (like table or thead)?
|
|
+1 |
1 similar comment
+1 |
I included jQuery 2.0 before angular (so jqLite is replaced by jQuery) and the problem is still there. |
any chances to get this one fixed? |
Conflicts: test/ng/compileSpec.js
+1 |
I didn't realize someone else had a patch for this. I think this is okay, but it's possible to move this into a closure so that in the future it might be extended to support other content types (like SVG content, for example). Also, the 'indexOf' strategy could potentially be problematic, as it is very strict --- I think a regexp is probably a nicer way to do this, in terms of being forgiving. My implementation is at #5235 |
If the first element in a template is a <tr>, <th>, <td>, or <tbody> tag, the HTML compiler will ensure that the template is wrapped in a <table> element so that the table content is not discarded. Closes angular#2848 Closes angular#1459 Closes angular#3647 Closes angular#3241
To work around limitations in jqLite, the template snippet is wrapped in
a
cannot be constructed inside a div. This patch takes special to properly
wrap caption, thead, tbody, tfoot, tr, th and td in tags that allow them
to be created.
Closes #1459