AngularJS- ng-model
Direktive
Beispiel
Binden Sie den Wert eines Eingabefelds an eine Variable im Geltungsbereich:
<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
= "John Doe";
});
</script>
Definition und Verwendung
Die ng-model
Direktive bindet ein HTML-Formularelement an eine Variable im Geltungsbereich.
Wenn die Variable nicht im Gültigkeitsbereich vorhanden ist, wird sie erstellt.
Syntax
<element ng-model="name"></element>
Unterstützt von den Elementen <input>, <select> und <textarea>.
Parameterwerte
Value | Description |
---|---|
name | The name of the property you want to bind to the form field. |
Verwandte Seiten
Winkel-Tutorial: Modelldirektive