Home>

angularjs ng-model directive

angularjs example

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

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

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.

grammar

<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)