I'm going to create a table with dynamic rows comes from APIs that look liks:
var app = angular.module("myapp", []);
app.controller("ListController", ['$scope', function($scope) {
$scope.personalDetails = [ {
"1": {
"name": "EZ-Catering",
"name_label": "EZ-Catering",
"address": "234 W. 11th St.\r\nBloomington IN 23484",
"address_label": "234 W. 11th St.\r\nBloomington IN 23484",
"contractDate_label": "2016-05-31",
"contractDate": "2016-05-31 00:00:00",
"currentClient": "1",
"currentClient_label":"true"
},
"2": {
"name": "Smithee Lawn Service",
"name_label": "Smithee Lawn Service",
"address": "555 Main St.\r\nEvansville IN 46234",
"address_label": "555 Main St.\r\nEvansville IN 46234",
"contractDate_label": "2016-05-08",
"contractDate": "2016-05-08 00:00:00",
"currentClient": "0",
"currentClient_label":"false"
}
}];
$scope.addNew = function(personalDetail){
};
$scope.remove = function() {
var newDataList=[];
$scope.selectedAll = false;
angular.forEach($scope.personalDetails, function(selected){
if(!selected.selected){
newDataList.push(selected);
}
});
$scope.personalDetails = newDataList;
};
$scope.checkAll = function () {
if (!$scope.selectedAll) {
$scope.selectedAll = true;
} else {
$scope.selectedAll = false;
}
angular.forEach($scope.personalDetails, function(personalDetail) {
personalDetail.selected = $scope.selectedAll;
});
};
}]);
The table should have a button to add more rows with empty fields.
Please notice that JSON data comes with numbering
"1": { ...
"2": { ...
I tried to use array.push but it's not working!