Latest web development tutorials

AngularJS form

AngularJS form input controls collection.

HTML controls

The following HTML input elements are called HTML controls:

  • input element
  • select elements
  • button element
  • textarea element

HTML form

HTML controls and HTML forms often coexist.

AngularJS form instance

First Name:

Last Name:

form = {{user}}

master = {{master}}

Application code

<Div ng-app = "myApp " ng-controller = "formCtrl">
<Form novalidate>
First Name: <br>
<Input type = "text" ng -model = "user.firstName"> <br>
Last Name: <br>
<Input type = "text" ng -model = "user.lastName">
<Br> <br>
<Button ng-click = "reset ()"> RESET </ button>
</ Form>
<P> form = {{{ user}} </ p>
<P> master = {{{ master}} </ p>
</ Div>

var app = angular.module ( 'myApp', []);
app.controller ( 'formCtrl', function ($ scope) {
$ Scope.master = {firstName: "John", lastName: "Doe"};
$ Scope.reset = function () {
$ Scope.user = angular.copy ($ scope.master);
$ Scope.reset ();
</ Script>

try it"
Note novalidate attribute is new in HTML5 in. Disable default authentication uses the browser.

Examples of analytical

ng-app directive defines AngularJS applications.

ng-controller directive defines the application controller.

ng-model directive bind the two input elements to the user object model.

formCtrl function sets the initial value of the master object, and defines the reset () method.

reset () method sets the user object is equal to the master object.

ng-click command called reset () method, and the call button is clicked.

novalidate property in the application is not necessary, but you need to use AngularJS form, for rewriting the standard HTML5 validation.