Mình đang viết javascript nhưng không hiểu sao đoạn code của mình nó lại có vấn đề.
scotchApp.controller('mainController', function ($scope, $http, UsersService) {
$scope.maxSize = 5;
$scope.bigCurrentPage = 1;
$scope.numPerPage = 5;
//-----------Get all and pagination----------------------------
UsersService.GetEmployeeList().success(function (d) {
$scope.Users = d.Data;
$scope.total = $scope.todos.length;
}).error(function () {
});
$scope.bigTotalItems = $scope.total;
$scope.$watch('bigCurrentPage + numPerPage', function () {
var begin = (($scope.bigCurrentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
$scope.Users = $scope.todos.slice(begin, end);
});
//------------------Insert User---------------------------------------
$scope.ThemNguoiDung = function () {
$http.post('/api/Users/', this.User).success(function (d) {
UsersService.GetEmployeeList().success(function (d) {
$scope.todos = d.Data;
$scope.total = $scope.todos.length;
}).error(function () {
});
}).error(function (error) {
alert('Thất bại');
});
}
})
Cái chỗ lấy dữ liệu thì chạy được. Nhưng khi mình Insert dữ liệu trong hàm $scope.ThemNguoiDung
thì sau khi success xong thì mình có gọi lại hàm load dữ liệu. Nhưng không hiểu sao nó lại không load lại. Xin hướng dẫn mình sai chỗ nào?