/** * */ angular.module("myApp").controller("employeeController", function ($scope, $http, $state) { console.log("Employee controller"); $scope.emp = { "username": "", "password": "", "firstName": "", "lastName": "", "emailAddress": "", "phoneNumber": "", "homeTown": "", "education": "", "department": "", "position": "" }; $scope.save = save; function save() { console.log($scope.emp); $http({ method: 'POST', url: "http://localhost:8081/list_employee/", data: $scope.emp }).then(function successCallback(response) { console.log(response); }, function errorCallback(response) { console.log(response) }); } $scope.updateEmp = updateEmp; function updateEmp(emp) { console.log('edit'); $state.go('createEmployee', {emp: emp}); } // HTTP DELETE- delete employee by Id // Call: http://localhost:8080/employee/{id} $scope.deleteEmp = function (emp) { $http({ method: 'DELETE', url: '/employee/' + emp.id }).then(function successCallback(response) { console.log(response); $scope.employess = response.data; }, function errorCallback(response) { console.log(response) }); }; // In case of edit $scope.edit = function (emp) { $scope.emp.username = emp.username; $scope.emp.password = emp.password; $scope.emp.firstName = emp.firstName; $scope.emp.lastName = emp.lastName; $scope.emp.emailAddress = emp.emailAddress; $scope.emp.phoneNumber = emp.phoneNumber; $scope.emp.homeTown = emp.homeTown; $scope.emp.education = emp.education; $scope.emp.department = emp.department; $scope.emp.position = emp.position; }; $http({ method: 'GET', url: "http://localhost:8081/list_employee/" }).then(function successCallback(response) { console.log(response); $scope.employess = response.data; }, function errorCallback(response) { console.log(response) }); // $scope.reload = reload; // function reload() { // $http.get("http://localhost:8081/employees") // success(function (data) { // $scope.employees = data.employees; // }); // $timeout(function(){ // $scope.reload(); // },3) // }; // $scope.reload(); // $scope.curPage = 1, // $scope.curPage = 1, // $scope.itemsPerPage = 3, // $scope.maxSize = 5; // // this.emp = $scope.emp; // // // $scope.numOfPages = function () { // return Math.ceil($scope.emp.length / $scope.itemsPerPage); // // }; // // $scope.$watch('curPage + numPerPage', function() { // var begin = (($scope.curPage - 1) * $scope.itemsPerPage), // end = begin + $scope.itemsPerPage; // // $scope.employess = $scope.emp.slice(begin, end); // }); });