Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

AngularJS Forms

Forms in AngularJS offer data binding and validation for input controls.

Input Controls

Input controls are HTML elements that include:

  • Input elements
  • Select elements
  • Button elements
  • Textarea elements

Data-Binding

Input controls enable data binding through the use of the ng-model directive.

<input type=”text” ng-model=”firstname”>

The application now has a property called firstname, which is linked to the input control through the ng-model directive, allowing access to the firstname property within a controller.

Example

<script>
var app = angular.module(‘myApp’, []);
app.controller(‘formCtrl’function($scope) {
  $scope.firstname = “John”;
});
</script>

It can also be referenced in other parts of the application.

Example

<form>
  First Name: <input type=”text” ng-model=”firstname”>
</form>

<h1>You entered: {{firstname}}</h1>