angularjs ng-model directive

angularjs example

Bind the value of the input box to the scope variable:

<! Doctype html>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<div ng-app="myapp" ng-controller="myctrl">
<input ng-model="name">
<p>The value of the input box is bound to the variable "name":</p>
var app=angular.module ("myapp", []);
app.controller ("myctrl", function ($scope) {
  $scope.name="john doe";
<p>This example demonstrates how to use the ng-model directive to bind the value of an input box to a scope variable.</p>

Definition and usage

The ng-model directive binds html form elements to the scope variable.

If there are no variables in the scope, It will be created.


<element ng-model="name"</element>

<input> ;,<select> ;,<textarea> ;, the element supports the directive.

Parameter value

value description
separator The name of the property i want to bind to the form field.

  • Previous IOS animation to achieve rain and cherry blossom special effects
  • Next Two JavaScript AES encryption methods (can be encrypted and decrypted with Java)