我在这个主题上发现了类似的帖子,但它们包括ngTable分页。我已禁用该功能,并且在成功发布后我无法刷新表。 tableParams.reload没有做任何事情。我也不明白为什么数据没有在其上更新,是不是Angular应该在模型改变时更新视图?
// Table
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 100, // count per page
sorting: {
foo: 'asc' // initial sorting
}
}, {
counts: [], // length of data
getData: function ($defer, params) {
$http.get('/api/apiMasterItem/')
.success(function (data, status) {
var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
});
}
});
$scope.editId = -1;
$scope.setEditId = function (pid) {
$scope.editId = pid;
}
//Post MasterItem
$scope.addMasterItem = function () {
var newMasterItem = $scope.newMasterItem
MasterItemPost.post(newMasterItem)
.success(function () {
notification.success();
}).error(function () {
notification.error();
})
console.log(newMasterItem);
$scope.tableParams.reload();
$scope.newMasterItem.MLItemCode = '',
$scope.newMasterItem.MLItemDescription = '',
$scope.newMasterItem.MLItemUOM = '',
$scope.newMasterItem.MLItemPrice = ''
};
答案 0 :(得分:2)
您也应该在收到数据后更新total
属性,无论是否使用分页
...
getData: function ($defer, params) {
$http.get('/api/apiMasterItem/')
.success(function (data, status) {
var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data;
// update table params
params.total(data.length);
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
});