Re: [angular.js] can one use ng-repeat without an html element?

7,211 views
Skip to first unread message

Dan Doyon

unread,
Jun 27, 2012, 6:18:45 PM6/27/12
to ang...@googlegroups.com
interesting concept

I would create a directive, 
set replace: true 
put non-html into the template, 

seems like it should work.

let us know!

--dan


On Jun 27, 2012, at 3:07 PM, Nik wrote:

I have this app where a project has many line items. And the JSON to be used has an array of projects, each of which has an array of line items. I am going to iterate the line items and display them in a table.
so 
what I want is something like this:

<table>
   ng-repeat="project in projects"
      <tr ng-repeat= "l in project.line_items">
           ...
       </tr>
</table>

Clearly I don't want the project to output anything, let alone that i can't quite use a div to contain the ng-repeat='project in projects' attribute, since it's in a table (that's more correct HTML use isn't it?)
The question is then, can I use ng-repeat without it generating any html element (but I do want it to generate child nodes of this element).

Thank you!

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/j2QFa6e5M9QJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Dan Doyon

unread,
Jun 27, 2012, 6:33:21 PM6/27/12
to ang...@googlegroups.com
hmmm, did a quick attempt got an error message 

'

oh well

Peter Bacon Darwin

unread,
Jun 27, 2012, 7:01:54 PM6/27/12
to ang...@googlegroups.com
I think you should be massaging the data in the controller, so that you can simply have one ng-repeat in the template.
Pete

Suller Andras

unread,
Jun 29, 2012, 2:26:24 AM6/29/12
to ang...@googlegroups.com
Maybe you can repeat on <tbody> element. One <table> can contain
multiple <tbody> elements, one for each project.

Andras

paul.k...@gmail.com

unread,
Jul 9, 2012, 9:28:07 AM7/9/12
to ang...@googlegroups.com


On Thursday, June 28, 2012 8:25:12 AM UTC+10, Andy Joslin wrote:
You're supposed to be able to use directives in comments, but I can't get it to work with ng-repeat.

ngRepeat can be used as an attribute only - its source code does not set 'restricted' and attribute is the default setting.

OTOH I don't see a strong reason why one can not write an Element level ng-repeat. Sounds like a very reasonable feature request.
Reply all
Reply to author
Forward
0 new messages