Ich habe einen einfachen Beispielcode, besteht aus 3 Variablen ab und testvar, testvar ist Summe von a und b, ich versuche zu verstehen, warum die Bindung nicht für Variable testvar funktioniert, wenn Wert von a ändert, ich habe mit seinem Modell eine Eingabe als erstellt.Angularjs Bind Problem
$scope.mymodel.testvar =$scope.mymodel.a+$scope.mymodel.b;
Wird a + b
zu testvar
nur einmal unter Verwendung der Anfangswerte von a
und b
: Wie dies erreicht werden kann, ist jede Hilfe stark
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<input ng-model="mymodel.a"><br>
Why this value does ot change on changing input:{{ mymodel.testvar}}
<br>
mymodel.a changes on input change: {{mymodel.a}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.mymodel={};
$scope.mymodel.a=1;
$scope.mymodel.b=2
$scope.mymodel.testvar =$scope.mymodel.a+$scope.mymodel.b;
});
</script>
<p>Test Binding.</p>
</body>
</html>
Vielen Dank! Ordentliche Erklärung – PortalGuy