We have four input elements, which are bound to the model user{first, last, email, age}.
1. user{first, last, email} are requiered.
2. email is from type='email'.
3. Age is from type='number', ng-maxlength='3' ng-minlength='1'
- If the form is not valid, submit-button is disabled.
- If You input values, the form-data will be shown as json-formatted on the fly.
- If You press "submit", the json-data will be send to the server, and return data will be shown as
"returnData" (Server is php-script and send new id from session).
{user | json}: {{user | json}}
returnData: {{returnData}}
Talking To Server
-
Convert data to Json
$scope.data = angular.toJson($scope.user);
-
Define send object
var sendObj = {
url: './data/addUser.php',
method: "POST",
data: $scope.data
};
-
Send data and receive the answer:
$http(sendObj).success(function (data, status, headers, config) {
$scope.returnData = data;
}).error(function (data, status, headers, config) {
$scope.status = status;
});