Instantly share code, notes, and snippets.

@hquach /app.js
Last active Nov 10, 2018

Embed
What would you like to do?
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