AngularJS Example:
HTML
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<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>
JavaScript
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;
}
}