AngularJS ng-Modell Richtlinie
ng-Modell Anweisung wird verwendet, um Anwendungsdaten zu HTML-Wert-Controller binden (input, select, TextArea-) aus.
ng-Modell Richtlinie
ng-model
Direktive kann Variablenwerte und AngularJS Domäne erstellt Bindungen ein.
AngularJS Beispiele
<Div ng-app = "myApp " ng-Controller = "myCtrl">
Name: <input ng-Modell = " name">
</ Div>
<Script>
var app = angular.module ( 'myApp', []);
app.controller ( 'myCtrl', function ($ scope) {
$ Scope.name = "John Doe";
});
</ Script>
Name: <input ng-Modell = " name">
</ Div>
<Script>
var app = angular.module ( 'myApp', []);
app.controller ( 'myCtrl', function ($ scope) {
$ Scope.name = "John Doe";
});
</ Script>
Versuchen »
Way Bindung
Zwei-Wege-Bindung, wenn Sie den Wert des Eingabefeldes ändern, wird der Wert der Immobilie wird auch AngularJS Bewertung sein:
AngularJS Beispiele
<Div ng-app = "myApp " ng-Controller = "myCtrl">
Name: <input ng-Modell = " name">
<H1> Sie Folgendes eingeben: {{name}} </ h1>
</ Div>
Name: <input ng-Modell = " name">
<H1> Sie Folgendes eingeben: {{name}} </ h1>
</ Div>
Versuchen »
Benutzereingabe prüfen
AngularJS Beispiele
<Form ng-app = "" name = "myForm">
E-Mail:
<Input type = "E - Mail" name = "myAddress" ng-Modell = "text">
<Span ng-show = "myForm.myAddress . $ Error.email"> ist keine gültige E - Mail - Adresse </ span>
</ Form>
E-Mail:
<Input type = "E - Mail" name = "myAddress" ng-Modell = "text">
<Span ng-show = "myForm.myAddress . $ Error.email"> ist keine gültige E - Mail - Adresse </ span>
</ Form>
Versuchen »
Das obige Beispiel, wird die Meldung in der ng-show
- Eigenschaft gibt true
Vitrine.
Anwendungsstatus
ng-model
Richtlinie sieht Statuswert (ungültig, schmutzig, berührt, Fehler ) für die Anwendungsdaten:
AngularJS Beispiele
<Form ng-app = "" name = "myForm" ng-init = "myText = '[email protected]'">
E-Mail:
<Input type = "E - Mail" name = "myAddress" ng-Modell = "myText" erforderlich> </ p>
<H1> Status </ h1>
{{MyForm.myAddress. $ Gültig}}
{{MyForm.myAddress. $ Schmutzig}}
{{MyForm.myAddress. $ Berührt}}
</ Form>
E-Mail:
<Input type = "E - Mail" name = "myAddress" ng-Modell = "myText" erforderlich> </ p>
<H1> Status </ h1>
{{MyForm.myAddress. $ Gültig}}
{{MyForm.myAddress. $ Schmutzig}}
{{MyForm.myAddress. $ Berührt}}
</ Form>
Versuchen »
CSS-Klasse
ng-model
Unterricht auf der Grundlage ihrer Staaten bieten CSS - Klassen für HTML - Elemente:
AngularJS Beispiele
<Style>
input.ng-invalid {
background-color: hellblau;
}
background-color: hellblau;
}
</ Style>
<Body>
<Form ng-app = "" name = "myForm">
Geben Sie Ihren Namen:
<Input name = "myAddress" ng -Modell = "text" erforderlich>
</ Form>
<Body>
<Form ng-app = "" name = "myForm">
Geben Sie Ihren Namen:
<Input name = "myAddress" ng -Modell = "text" erforderlich>
</ Form>
Versuchen »
ng-model
Anweisung basierend auf dem Zustand Formularfeld hinzufügen / entfernen Sie die folgenden Kategorien:
- ng-leer
- ng-nicht-leer
- ng-berührt
- ng-unberührt
- ng-gültig
- ng-ungültig
- ng-dirty
- ng anhängige
- ng-pristine