回答
看一看的plunkr。您可以添加或刪除控制器內維護的陣列中的列以更新您的表。
https://plnkr.co/edit/w90MlA?p=preview
HTML -
<div ng-app="demoApp" ng-controller="demoCtrl">
<table border="1">
<thead>
<tr>
<th ng-repeat="col in cols">{{col}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rows">
<td ng-repeat="col in cols">
{{row[col]}}
</td>
</tr>
</tbody>
</table>
</div>
JS -
// Code goes here
var demoApp = angular.module("demoApp", []);
demoApp.controller("demoCtrl", ['$scope', function($scope){
$scope.cols = ['A', 'B', 'C'];
$scope.rows = [
{
'A': "1",
'B': "2",
'C': "3",
'D': "4"
},
{
'A': "5",
'B': "6",
'C': "7",
'D': "8"
},
{
'A': "11",
'B': "21",
'C': "31",
'D': "41"
}
]
}]);
希望這有助於。
謝謝,我想我喜歡列名中的10列名稱,默認情況下,我會顯示5列,上面的表會有偏好下拉菜單中會有添加列,刪除列並保存.i添加列,其餘列名將從列表中顯示.in刪除列列名中顯示的列ble必須在那裏 –
如果你從首選項刪除列名 - >刪除列 - >列名,然後刪除的列名必須添加到首選項 - >添加列(下拉) –
看看更新的plunkr https:/ /plnkr.co/edit/w90MlA?p=preview – codeomnitrix
維護一個名稱爲列的數組並根據您的需要更新它,以添加和刪除列,並在表中放置'
然後它將顯示數組中的所有標題 –
一旦檢查上面的圖像 –