Forms in AngularJS offer data binding and validation for input controls.
Input controls are HTML elements that include:
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.
<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.
<form> First Name: <input type=”text” ng-model=”firstname”> </form> <h1>You entered: {{firstname}}</h1> |