ich ein Problem mit kantigem Anwendungsbereich haben:Angular Umfang nicht aktualisiert, auch mit apply()
Init Eckig:
<html lang="en" ng-app="ant101App" ng-controller="regFormController as reg">
Script:
script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script>
var app = angular.module('ant101App',[]);
app.controller('regFormController', function() {
this.message = null;
if ((''+this.fname).length > 15) {
this.message = 'First name should be less than 16 characters!';
}
});
</script>
HTML:
<p>{{reg.message}}</p>
<input ng-model="reg.fname" type="text" name="firstname" class="afirst-name-box" placeholder="First name" required>
Wenn ich Vorname eingeben, reg .message wird nicht aktualisiert. Wenn ich aplly(), ist es auch Fehler verursacht hat, und nur angezeigt {{reg.message}} in HTML-Seite
<script>
var app = angular.module('ant101App',[]);
app.controller('regFormController', function() {
this.message = null;
this.$apply(function(){
if ((''+this.fname).length > 15) {
this.message = 'First name should be less than 16 characters!';
}
});
});
</script>
So wie kann ich reg.message aktualisieren, wenn reg.fname geändert?
Sie $ scope, um injizieren sollte AngularJS Bindungen zu nutzen und anzuwenden $ –
http: //www.w3schools .com/angular/angular_scopes.asp Hilfe für $ scope –
@MohammadMc Nein, OP benötigt $ scope nicht. Und $ gelten auch. – dfsq