-
Notifications
You must be signed in to change notification settings - Fork 27.5k
ngRepeat with DL / DD / DT #1891
Comments
second this. I've been having this issue for a while. |
@IgorMinar did some work on a comment-based ng-repeat (#1646) but since comments don't play so well on all browsers it is not likely to be merged. Instead they are looking at an alternative solution, probably with either "start and end repeat tags" or "start-repeat and number of elements to repeat label" |
How about allowing templates inside pairs like {{ }} maybe: On a related note, i have a similar issue with On Tue, Jan 29, 2013 at 12:38 PM, Pete Bacon Darwin <
|
I just ran into this issue with a table that wants to generate two 'td' elements per object in an array. |
+1 for adding this feature. Just ran into this same limitation. |
👍 |
Same problem here. I'd love to see something like "ng-repeat-children" repeating only the children but not the current element or a kind of "ng-omit-tag" (which removes the current tag but leaves children in place) to be used together with ng-repeat. This would avoid tons of invalid markup generated to workaround this problem. |
Do not fully understand the limitation that is under discussion. Why putting the ng-repeat on the parent element does work? http://jsfiddle.net/JyWdT/13/ |
lgalfaso, Your fiddle creates multiple definition lists each with one definition. The desired output is one definition list with multiple definitions. Or in my case, I need to create a pair of "td" elements for every item in an array. [{name:dan, age:15}, {name:steve, age:21}] and I need to output: <tr><td>dan</td><td>15</td><td>steve</td><td>21</td></tr> There is no way to accomplish that with angular at this time. |
can't you do that by putting the ng-repeat on the tr element? http://plnkr.co/edit/lJvkOpz0NnKWcfEeM4lE?p=preview On Sun, Apr 21, 2013 at 2:24 PM, zilles [email protected] wrote:
|
Oh, I see, disregard my previous comment
|
As I just encounter the dl / dt + dd issue, I confirm that a new ng-repeat-children (or ng-repeat-inner) is a missing mandatory directive. |
+1 |
Proposal for a new directive ng-repeat-inner. If this proposal is ok, then will modify all the guides |
I think it would be better to use the same Something like this should then work: <dl>
<!-- ng-repeat="(name, definition) in myList" -->
<dt>{{name}}</dt>
<dd>{{definition}}</dd>
<!-- /ng-repeat -->
</dl> Not sure exactly how the beginning and end of the block to be repeated would be achieved ( |
Given that minifiers can kill comments and other issues with comments, I
would become:
On Tue, Apr 23, 2013 at 3:54 PM, Mani Tadayon [email protected]:
|
maxcan, I can see the advantages of "single-root", since you keep the source html valid, but that construct doesn't let you add anything else inside the "dl" tag... A fixed definition for example that you want to include before your loop of dynamic definitions. lgalfaso's solution would handle that. |
@maxcan without a big rework or a performance hit, I do not think it is possible to add this property ng-repeat-single-root (well, add it and make it dynamic based on it). The rational is that there is a high chance that a change on this property would cause a recompilation [and nobody likes recompilations] |
I like @bowsersenior's suggestion, but I'd prefer this as the closing comment: |
That's a shame on the performance hit. Anyway, I strongly endorse On Wed, Apr 24, 2013 at 1:58 PM, Dean Sofer [email protected]:
|
I concur with @ProLoser that |
I dont mind discarding them as long as there is a way to do this without On Wed, Apr 24, 2013 at 2:41 PM, Mani Tadayon [email protected]:
|
+1 to @lgalfaso's ng-repeat-inner. I'd finally like something that just gets this done. |
Knockout does this with comments. I'm trying to port something I did with the dl tag in knockout and it seems like that is not possible until this issue is addressed. |
Add a new directive ng-repeat-inner that will behave as ng-repeat but the template that is being repeated is the inner of the element and not the element itself Closes angular#1891
This is my opinion, so without the input from @mhevery or @IgorMinar, take this with a grain of salt. |
Ok, it looks like the is a real issue with multi-element directives that are at the same level at the DOM. Updated the PR with a fix for this issue |
Fixes such as ng-repeat-inner or ng-repeat-next only solve one of countless situations where binding behaviors to actual DOM nodes will limit you. Instead of patching every directive individually you can solve this for the entire framework by adding support for virtual nodes which don't render in the actual tree. The idea of using comments is similar, but it results in unsightly, hard to read code and you still need a way to name that node and close it somehow. Instead of inventing a new comment node syntax, use existing HTML syntax. Think about it as a concept similar to, say, SASS silent classes: <div id="myComplexList">
<ng-virtual ng-repeat="...">
<a></a>
<b></b>
<c></c>
</ng-virtual>
</div>
Result:
<div id="myComplexList">
<a></a>
<b></b>
<c></c>
<a></a>
<b></b>
<c></c>
<a></a>
<b></b>
<c></c>
...
</div> |
+1 to the general idea but I'd go for something like ng-repeat-group. <ng-repeat-group="b in ches">
// group markup to be repeated here
</ng-repeat-group> |
I like the idea of a virtual nodes, but I'm against it becoming a general solution for the problem here. If at all possible, I'd like to limit the creation of any artificial containers. While the container may not show up on the html of the overall result, it would start cluttering up the html code that needs managing. In many cases, we'll be needing some container to contain what we want to repeat. ex:
(the container here being the [tr]s) using the virtual node solution proposed would turn this into:
making a redundant container: even this two line addition makes me feel uncomfortable thinking what it'd be like if the code got longer. Another issue is that it'll start to make tedious trying to grasp what level of dom the code is currently in.
using virtual nodes turns this into:
The repetition of the first 3 trs and the final tr are on the same level, but if I was just to take a quick skim through the code, there's a chance I'll mistake them as different levels, or I'll start finding myself tediously calculating (perhaps incorrectly) what level the code's working on, especially if these things start nesting. |
Here is a particular version of syntax I like (of kind B):
|
@stanvass your proposal is a variation of what @IgorMinar posted as syntax X, the main issue is that browser support is just not there |
I've just realised that having both a
It would be nice if we could also have a
|
@daegon123 if you want to repeat a single element, just do <tr>
<td ng-repeat="...">repeat this</td>
</tr> No need for |
@lgalfaso Thanks, it seems I've gotten caught up in the proposed syntax so much that I forgot what we already had. Hope we get the ng-repeat-start/end realized soon. |
I think this issue is not about simply repeating one element. Its more about how to repeat a set of elements without repeating its parent. i.e. |
Syntax X is the only one that is well defined once you start nesting repeats. How would you write the following in Syntax A-D: <template>
<dl>
<ng repeat="book in myList">
<dt ng-repeat="author in book.authors">{{author.name}}</dt>
<dd>{{book.title}}</dd>
<dd>{{book.description}}</dd>
</ng>
</dl>
</template> |
It is better suggestion. -----Original Message----- I've just realised that having both a
It would be nice if we could also have a
Reply to this email directly or view it on GitHub: |
+1, this is a big limitation. |
👍 look forward to seeing a solution for this! I'm going with using |
Would #2783 resolve this? |
Yes. We have a solution that just landed: e46100f I'm closing this issue. |
I got error: <table>
<tr ng-repeat-start="value in [1,2,3,4]">I get repeated</tr>
<tr ng-repeat-end>I also get repeated</tr>
</table> |
Also getting the issue as gevgeny states. <tr>
<td data-ng-repeat-start="column in selectedItem.Beds" class="text-center">Avail. Beds</td>
<td data-ng-repeat-end>Extra Bed Spaces</td>
</tr> |
How would #2783 resolve this:
.... It need to output something like this:
What would it be the syntax? |
@ChrisCinelli Try use
|
So hgroup seems has been remove from HTML5 ( http://html5doctor.com/the-hgroup-element/ ), beside that, as I was saying the problem is more complex and the header tags were used just for example. |
For the specific output you're looking for, have you considered CSS See: On Tue, Jun 18, 2013 at 2:46 PM, Chris Cinelli [email protected]:
|
I used the header as an example to make it clear... in reality I have a relatively complex The only solution that I found so far is to linearize the data structure in Javascript and use a ng-switch for different levels and it will require me an extra div level. |
Can you make directives for each level? I'm not sure what kind of On Tue, Jun 18, 2013 at 4:27 PM, Chris Cinelli [email protected]:
|
This is how it looks like: http://d.pr/i/GSX4 The current view is pretty logic-less and make it relatively clear what is going on. This to me looks messier, less coesive and less readable. Given the data structure that has all the info to display this panel, why do I need to use code in a different file (the module/controller) when the logic is completely view related and very specific of this view? IMHO, the controller should be (and it is right now in the current implementation):
Sure I can add a few extra divs and change the CSS, but if this is necessary to make it work with Angular, it feels that Angular is in the way of how it is convenient and elegant to get the things done here. |
I find the databinding in KnockoutJS, which allows both bindings to an html element For more details on Knockout's "containerless" option: |
+1 for @mg1075 virtual syntax. |
Is there any timeframe on when (and how?) ngRepeat is going to handle Definition Lists?
In case you are not familiar with the problem: Currently ngRepeat works with single elements. For most HTML, this works fine.. however for definition lists such as
<dl>
, this does not work. Why? Because definition lists uses multiple elements to define a single list item.Now, there are multiple ways around this, but reading here suggests that Angular is going to use comments to support repeating elements.
Any idea on when this feature is going to be implemented? Or if there is a somewhat stable branch that can be merged in to address this? The existing solutions currently are very hacky, against standards, and prone to breaking code in IE/etc.
Thoughts?
edit: By "stable branch that can be merged", i meant a branch that i could fork to run on my site and address this issue until the code is officially merged in. My apologies for the poor wording :)
The text was updated successfully, but these errors were encountered: