@Thach-Huynh :
ban đầu bạn hãy khai báo một array:
var dateNow = new Date();
$scope.listTime = [
{start: dateNow, end: dateNow, last: dateNow, delay: dateNow}
];
Chỗ code html tạo table bạn dùng ng-repeat cho <tr>:
<tr ng-repeat="time in listTime">
<td ng-model="time.start">
<td ng-model="time.end">
<td ng-model="time.last">
<td ng-model="time.delay">
</tr>
button add giữ nguyên:
<button ng-click="insertRow()">Add</button>
nhưng trong controller bạn sẽ khai báo hàm như sau:
$scope.insertRow = function () {
$scope.listTime.push({start: dateNow, end: dateNow, last: dateNow, delay: dateNow});
}
button delete cho nó nằm trong <tr> ng-repeat ở trên để get dc $index của mỗi item.
<table>
<thead>
<tr>
<th></th>
<th>Start time</th>
<th>End time</th>
<th>Last time</th>
<th>Delay time</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="time in listTime">
<td><i class="glyphicon glyphicon-ok-circle"></i></td>
<td><input type="time" class="form-control" ng-model="time.start" id="start-time{{$index}}" placeholder="start time"></td>
<td><input type="time" class="form-control" ng-model="time.end" id="end-time{{$index}}" placeholder="end time"></td>
<td><input type="number" class="form-control" ng-model="time.last" id="last-time{{$index}}" placeholder="last time"></td>
<td><input type="number" class="form-control" ng-model="time.delay" id="delay-time{{$index}}" placeholder="delay time"></td>
<td><button class="button add-item-button" ng-click="deleteRow($index)"><i class="glyphicon glyphicon-remove"></i></button> </td>
</tr>
</tbody>
</table>
khai báo hàm trong controller:
$scope.deleteRow= function (index) {
$scope.listTime.splice(index, 1);
}
button save and submit:
<button ng-click="saveAndSubmit()"></button>
controller:
$scope.saveAndSubmit = function () {
//send $scope.listTime
}