是否可以通过ng-repeat创建一个包含多列的表?
我不确定是否有更有说服力的方式,所以在下面我发布了一个样本模板。这不起作用,因为周围的div打破了表。
例如:
<table>
<tr>
<div ng-repeat="num in [1,2,3]">
<td>1</td>
<td>2</td>
<td>3</td>
<td>Avg</td>
</div>
</tr>
预期产出:
<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>
答案 0 :(得分:2)
<table>
<tr ng-repeat="s in Subjects">
<td>{{ s.name }}</td>
<td>{{ s.address }}</td>
</tr>
</table>
希望这会让你好起来!
答案 1 :(得分:0)
当然这是可能的。要获得预期的输出,只需使用special repeat start and end points ng-repeat-start
和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() {
}
})();
&#13;
<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>
&#13;