I am using ng-table in angular js. My problem is delete one record in my table the data is not reloaded. this is my code
myapp.controller('aamListAssignment', ['$scope', '$http', 'ngTableParams', function ($scope, $http, ngTableParams) {
$scope.data = [];
$scope.listPromise = null;
$scope.$watch("data", function () {
$scope.tableParams.reload();
});
$scope.list = function () {
$scope.listPromise = $http.get('./ccs/assignment/all').success(function (data) {
$scope.data = data;
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 2 // count per page
}, {
counts: [],
total: $scope.data.length, // length of data
getData: function ($defer, params) {
$defer.resolve($scope.data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});
};
$scope.removeAssignment = function (id) {
$scope.value = true;
$scope.Url = "./ccs/assignment/removeAssignment/" + id;
$http.get($scope.Url).success(function (data) {
console.log('after delete: ' + $scope.id);
// $location.path('aam/listAssignment/');
$scope.list();
});
};
$scope.list();
}]);
Execute time two types of errors occurred in a console page that is
"Error: $scope.tableParams is undefined..............
and
"Error: h.$scope is null..........
please help me to this problem.
I am using another way, this time reload is working,but pagination not working.the code is
myapp.controller('aamListAssignment', ['$scope', '$http', 'ngTableParams', function ($scope, $http, ngTableParams) {
$scope.tableParams = {};
$scope.data = [];
$scope.listPromise = null;
$scope.list = function () {
$scope.listPromise = $http.get('./ccs/assignment/all').success(function (data) {
$scope.data = data;
$scope.tableParams.reload();
});
};
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 6 // count per page
}, {
counts: [],
total: $scope.data.length, // length of data
getData: function ($defer, params) {
$defer.resolve($scope.data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
$scope.removeAssignment = function (id) {
$scope.value = true;
$scope.Url = "./ccs/assignment/removeAssignment/" + id;
$http.get($scope.Url).success(function (data) {
console.log('after delete: ' + $scope.id);
$scope.list();
});
};
$scope.list();
}]);
if you just request data ,and then just paginate on array,there 's must be no problem,if you need to paginate every request then have a look here ,and don't forget
to iterate over $data
<tr ng-repeat="user in $data">
in your plunk you should add total
call,like here
total: data.length, // length of data
getData: function($defer, params) {
//need fo pagination!!
params.total(data.length);
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
your working plunk with editing above