AngularJS Forms
AngularJS forms are collections of input controls.
HTML Controls
The following HTML input elements are called HTML controls:
- input element
- select element
- button element
- textarea element
Data Binding
Input controls use the ng-model directive to achieve data binding.
Through the above code, the application has a property named firstname.
It is bound to your application using the ng-model directive.
The firstname property can be used in the controller:
Example
Try it Yourself »
It can also be used elsewhere in the application:
Example
Try it Yourself »
Checkbox
The value of a checkbox is true or false. It can be bound using the ng-model directive, and its value can be used in the application:
Example
After the checkbox is selected, the h1 tag content is displayed:
Try it Yourself »
Radio Buttons
We can use ng-model to bind radio buttons to your application.
Radio buttons use the same ng-model and can have different values, but only the value of the selected radio button will be used.
Example
Display information based on the selected radio button:
Try it Yourself »
The value of myVar can be dogs, tuts, or cars.
Drop-down Menus
You can bind the drop-down menu to your application using the ng-model directive.
The value of the ng-model attribute is the option you selected in the drop-down menu:
Example
Display information based on the selected drop-down menu option:
Try it Yourself »
The value of myVar can be dogs, tuts, or cars.
HTML Forms
HTML forms usually exist together with HTML controls.
AngularJS Forms Example
form = {{user}}
master = {{master}}
Application Code
Try it Yourself »
![]() |
novalidateThe attribute is new in HTML5. It disables the browser's default validation. |
|---|
Example Explanation
ng-appThe directive defines the AngularJS application.
ng-controllerThe directive defines the application controller.
ng-modelThe directive binds two input elements to the model's userobject.
formCtrlThe function setsmasterthe initial value of the object, and definesreset()the method.
reset()The method setsuserthe object equal tomasterthe object.
ng-clickThe directive callsreset()the method, and it is called when the button is clicked.
The novalidate attribute is not required in the application, but you need to use it in AngularJS forms to override the standard HTML5 validation.
Other Extensions