我正在使用 angularjs,我想用 ng-repeat 创建动态行,但无法实现。看到我的代码后我会清除。这是我的代码和 jsfiddle :-
td.controllers.js
function TodoCtrl($scope) {
$scope.products = [{
name: 'Abc'
}, {
name: 'Bil'
}, {
name: 'Smart'
}];
}
td.html
<div ng-app>
<div ng-controller="TodoCtrl">
<table class="table">
<thead>
<tr>
<th rowspan="2">Month</th>
<th ng-repeat="product in products" colspan="2">{{product.name}}</th>
</tr>
<tr>
<th>A</th> //I want to dynamic it
<th>B</th> //
</tr>
</thead>
</table>
</div>
</div>
我想要的输出是:-
-----------------------------
Month | Abc | Bil | Smart
| A|B | A|B | A|B
----------------------------
最佳答案
<div ng-app>
<div ng-controller="TodoCtrl">
<table class="table">
<thead>
<tr>
<th rowspan="2">Month</th>
<th ng-repeat="product in products">{{product.name}}</th>
</tr>
<tr>
<th></th> <!--I want to dynamic it-->
<th ng-repeat="product in products">A|B</th>
</tr>
</thead>
</table>
</div>
</div>
试试这个代码 这里表头和表数据都是动态创建的。
如果您遇到任何问题,请告诉我
关于javascript - 使用 ng-repeat 创建动态列和行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43580453/