REST API Using Angular JS

var API_URL = ""; $scope.employee = { username: "jonpecson", firstname: "Jon", lastname: "Pecson" } //Retrieve all employees from API $http.get(API_URL + "employees") .success(function(response) { $scope.employees = response; }); //Save new record $scope.save = function(modalstate, id) { var url = API_URL + "employees"; $http({ method: 'POST', url: url, data: $.param($scope.employee), headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function(response) { console.log(response); location.reload(); }).error(function(response) { console.log(response); alert('This is embarassing. An error has occured. Please check the log for details'); }); } //Delete record $scope.confirmDelete = function(id) { var isConfirmDelete = confirm('Are you sure you want this record?'); if (isConfirmDelete) { // Deletes an employee record with a specified id $http({ method: 'DELETE', url: API_URL + 'employees/' + id }). success(function(data) { console.log(data); location.reload(); }). error(function(data) { console.log(data); alert('Unable to delete'); }); } else { return false; } }
CRUD sample using AngularJS using Laravel as a backend

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.