I am trying to post data by using angular HTTP post method. My requirement is once the form is field than on clicking the Submit button the HTTP post method is called by collecting all the field input value. I have been tried this simple snippets code, but don't know how to collect form field value and then calling the HTTP post method.
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title> Simple Signup page</title>
</head>
<body>
<h1><b>signup</b></h1>
<form ng-controller="signupController">
First Name:<input type="text" ng-model="first_name" placeholder="enter first_name"><br>
<br> Last Name:<input type="text" ng-model="last_name" placeholder="enter last_name"><br>
<br> Email-id:
<input type="text" ng-model="email_id" placeholder="enter email_id"><br>
<br> User-id:
<input type="text" ng-model="user_id" placeholder="enter user_id"><br>
<br> Password:
<input type="text" ng-model="password" placeholder="enter password"><br>
<br> Mobile:
<input type="text" ng-model="mobile" placeholder="enter mobile"><br>
<br>
<input type="button" ng-click="Signup(user)" name="name" value="Signup" </form>
<script src="script2.js"></script>
<script>
function signupController($scope, $http) {
$scope.first_name = "bht";
$scope.last_name = "sh";
$scope.email_id = "[email protected]";
$scope.user_id = "bh5";
$scope.password = "root";
$scope.mobile = "8145455547";
// trying to store data in user object
var user = {
first_name: "$scope.first_name",
last_name: "$scope.last_name",
email_id: "$scope.email_id",
user_id: "$scope.user_id",
password: "$scope.password",
mobile: "$scope.mobile"
};
console.log("user array is:", user);
$scope.Signup = function(user) {
$http.post("http://localhost:1430/user/signup/user?tableName=signup", user).success(function(user) {
user.data
});
};
};
var myApp = angular.module("myApp", []);
myApp.controller("signupController", signupController);
</script>
</body>
</html>