AngularJS ng-model instruktion

Definition and Usage

ng-model The directive binds HTML form elements to variables in the scope.

If the variable does not exist in the scope, it will be created.

Related Pages

Angular Tutorial:ng-model directive

Example

Bind the value of the input field to a variable in the scope:

<div ng-app="myApp" ng-controller="myCtrl">
    <input ng-model="name">
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.name = "Bill Gates";
});
</script>

Prova själv

Syntax

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

Påverkas av <input><select> och <textarea> Element som stöds.

Parametrar

Parametrar Beskrivning
name Namnet på egenskapen som du vill binda till formulärfältets attribut.