AngularJS changing model value in one controller triggers model update in
others
In this example: http://jsfiddle.net/m8xtA/
<div ng-app>
<div ng-controller="A"><input ng-model="m">
{{a()}} - {{counter}}
</div>
<div ng-controller="B"><input ng-model="m">
{{b()}} - {{counter}}
</div>
</div>
JS
function A($scope) {
$scope.m='a';
$scope.counter = 0;
$scope.a = function(){
$scope.counter++;
return $scope.m;
}
}
function B($scope) {
$scope.m='b';
$scope.counter = 0;
$scope.b = function(){
$scope.counter++;
return $scope.m;
}
}
as soon as I change the input value in controller A, it will call b()
which is in a totally separate controller. Why would it recalculate the
model objects in the other controllers? Is there a way to avoid this?
No comments:
Post a Comment