been trying to get the value of form using angular js on form submit. someone help me what to do. I am new to angular JS.
<div id="content" ng-app="TryApp" ng-controller="AppController" ng- submit="submit()">
<input type="text" placeholder="first name" name='name' ng- model="user.Name"/>
<br>
<input type="text" placeholder="email address" name="name" ng-model="user.email"/>
<br>
<input type="text" placeholder="age" name="age" ng-model="user.age"/>
<br>
script.
App.controller('AppController', function ($scope){
)}
The FormData interface provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the fetch() or XMLHttpRequest.send() method. It uses the same format a form would use if the encoding type were set to "multipart/form-data" .
The $ in AngularJs is a built-in object.It contains application data and methods.
Forms in AngularJS provides data-binding and validation of input controls.
The ng-submit directive specifies a function to run when the form is submitted. If the form does not have an action ng-submit will prevent the form from being submitted.
var app = angular.module('TryApp', [], function() {})
app.controller('AppController', function($scope) {
$scope.user = {};
$scope.submit = function() {
//here $scope.user will have all the 3 properties
alert(JSON.stringify($scope.user));
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div id="content" ng-app="TryApp" ng-controller="AppController">
<form ng-submit="submit()">
<input type="text" placeholder="first name" name='name' ng-model="user.Name" />
<br>
<input type="text" placeholder="email address" name="name" ng-model="user.email" />
<br>
<input type="text" placeholder="age" name="age" ng-model="user.age" />
<br>
<input type="submit" value="Save" />
<p>{{user | json }}</p>
</form>
</div>
Note: for submit handler to work, you need a form and a submit button as shown above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With