我想通過使用角度HTTP發佈方法發佈數據。我的要求是一旦表單字段比單擊提交按鈕通過收集所有字段輸入值調用HTTP post方法。我已經嘗試過這個簡單的片段代碼,但不知道如何收集表單字段值,然後調用HTTP post方法。通過從html表單輸入類型文本中收集數據值發送角度http post中的數據
<!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>