Last active
November 10, 2018 03:04
-
-
Save hquach/a0176069f9d2ad7cb92658753b50d38e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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