0

Is it possible to create a table with multiple columns via an ng-repeat?

I'm not sure there is a more eloquent way to ask, so below I've posted a sample template of sorts. This does not work since the surrounding div breaks the table.

For example:

<table>
  <tr>
    <div ng-repeat="num in [1,2,3]">
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td>Avg</td>
    </div>
  </tr>

Expected Output:

<table>
  <tr>
    <td>1</td> <td>2</td> <td>3</td> <td>Avg</td>
    <td>1</td> <td>2</td> <td>3</td> <td>Avg</td> 
    <td>1</td> <td>2</td> <td>3</td> <td>Avg</td> 
  </tr>
</table>
2
  • Could you provide us more details? Your question couldn't be more unclear. Expected output, set of datas, etc. Commented Apr 13, 2017 at 21:37
  • @Sakuto See edits :| Commented Apr 13, 2017 at 21:44

2 Answers 2

2

yes it totally is possible. you just dont need a div. :p

<table>
  <tr ng-repeat="s in Subjects">
    <td>{{ s.name }}</td>
    <td>{{ s.address }}</td>
  </tr>
</table>

hope this gets ya rolling!

Sign up to request clarification or add additional context in comments.

5 Comments

But this will create a new table row. Suppose I want them all in the same row: see my edits for a sort of desired outcome.
oh great, thanks for updating our question. if adding repeat to <tr> creates a new row, adding repeat to <td> will create more rows within that column. :)
Sorry again Matt, I think what I should mean to ask is. Can I group <td> within a div somehow. Because I want this all within one row
stackoverflow.com/questions/21644493/… I found something I think! Thanks guys
@user3007703 Check my answer, I believe it's much simpler than the question you have referenced.
0

Of course this is possible. To get your expected output, simply use the special repeat start and end points ng-repeat-start and ng-repeat-end:

// app.js
(function() {

  'use strict';

  angular.module('app', []);

})();

// main.controller.js
(function() {

  'use strict';

  angular.module('app').controller('MainController', MainController);

  MainController.$inject = [];

  function MainController() {


  }

})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>

<div ng-app="app" ng-controller="MainController as MainCtrl">
  <table>
    <tr>
      <td ng-repeat-start="num in [1,2,3]">1</td>
      <td>2</td>
      <td>3</td>
      <td ng-repeat-end>Avg</td>
    </tr>
  </table>
</div>

1 Comment

This is exactly what I was looking for! Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.