In my code (snippet example below), I have a variable that is bound to an input box using the ng-model directive. Then, I have another variable that, for the purpose of my project, is dependent on that bound variable.
How do I keep (in the case of the example below) bar up to date when foo changes?
I tried using the $scope.$watch function call (which I show the syntax I used below), but the bound function does not get called when the user types something into the input box.
HTML
...
<div ng-controller="exampleController as ctr">
...
<div><input type="number" ng-model="ctr.foo" /></div>
<div>{{ ctr.bar }}</div>
</div>
Javascript
app.controller('ExampleController', function($scope){
var local = this;
this.foo = 5;
this.bar = 10;
this.updateBar = function(){
this.bar = this.foo * 2;
};
$scope.$watch('foo', function(){
local.updateBar();
});
});
Note: All of this is just example code to show what my problem is.