Being new to AngularJS my understanding of the below syntax, from my limited experience, was that it made a two-way data binding between the view and model which means if the input in the view changes the model changes to match AND vice versa.
<form ng-controller="StartUpController">
Starting: <input ng-change="computeNeeded()"
ng-model="funding.startingEstimate">
Recommendation: {{funding.needed}}
</form>
<script>
function StartUpController($scope) {
$scope.funding = { startingEstimate: 0 };
$scope.computeNeeded = function() {
$scope.needed = $scope.startingEstimate * 10;
};
}
</script>
Then I read that if other elements are bound to the same variable in the model or if the database may update the model then $watch() must be used so that the view updates. But from my novice perspective this is what two-way data binding is doing already.
<form ng-controller="StartUpController">
Starting: <input ng-model="funding.startingEstimate">
Recommendation: {{funding.needed}}
</form>
<script>
function StartUpController($scope) {
$scope.funding = { startingEstimate: 0 };
computeNeeded = function() {
$scope.funding.needed = $scope.funding.startingEstimate * 10;
};
$scope.$watch('funding.startingEstimate', computeNeeded);
}
Could someone clarify for me... Many Thanks in advance.