Skip to content

Instantly share code, notes, and snippets.

@hquach
Last active November 10, 2018 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hquach/a0176069f9d2ad7cb92658753b50d38e to your computer and use it in GitHub Desktop.
Save hquach/a0176069f9d2ad7cb92658753b50d38e to your computer and use it in GitHub Desktop.
var fetch = angular.module('myapp', []);
fetch.controller('userCtrl', ['$scope', '$http', function ($scope, $http) {
// Get all records
$http({
method: 'post',
url: 'CRUD.php',
data: {request_type:1},
}).then(function successCallback(response) {
$scope.users = response.data;
});
// Add new record
$scope.add = function(){
$http({
method: 'post',
url: 'CRUD.php',
data: {fname:$scope.fname,lname:$scope.lname,username:$scope.username,request_type:2},
}).then(function successCallback(response) {
$scope.users.push(response.data[0]);
});
}
// Remove record
$scope.remove = function(index,userid){
$http({
method: 'post',
url: 'CRUD.php',
data: {userid:userid,request_type:3},
}).then(function successCallback(response) {
$scope.users.splice(index, 1);
});
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment