Hi,
I created a simple datatable using angular js. When I run this code, the datatable shows up properly. I wrote ng-click to delete the particular row from datatable. When i test the code below and click on any of the lastnames the element is getting removed from array persons but not from datatable. Am I doing anything wrong here? Please help. I have attached complete code(example.html).
My HMTL Code:
<div ng-controller="simpleCtrl">
<table datatable="ng">
<thead>
<tr>
<th>ID</th>
<th>FirstName</th>
<th>LastName</th>
</tr>
</thead>
<tbody>
<tr dt-rows ng-repeat="person in persons">
<td>{{ person.firstName }}</td>
<td><a ng-click='remove(person)'>{{ person.lastName }}</a></td>
</tr>
</tbody>
</table>
</div>
Controller code:
controller('simpleCtrl', function($scope, $http) {
$scope.persons = [];
$http.get('data.json').success(function(persons) {
$scope.persons = persons;
});
$scope.remove = function(item){
var index = $scope.persons.indexOf(item);
console.log(index);
$scope.persons.splice(index,1);
console.log($scope.persons);
}
});
Thanks,
Sravya