Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app='app'>
  <h4> outputCtrl </h4>
  <div ng-controller='outputCtrl'>
    <input ng-model='input' type=number />
    <pre> {{ result }} </pre>
  </div>
  
  <h4> outputChildCtrl </h4>
  <div ng-controller='outputChildCtrl'>
    <input ng-model='input' type=number />
    <pre> {{ result }} </pre>
  </div>
</body>
</html>
 
app = angular.module('app',[]);
app.controller('parentCtrl', function($scope) { 
  $scope.mult = 10;
  $scope.processing_function = function (n) { 
    return n * $scope.mult;
  };
});
app.controller('outputCtrl', function($scope) { 
  $scope.input = 0;
  $scope.result = 1;
  
  $scope.proccess_input = function () {
    $scope.result += 1;
    console.log('outputCtrl processing ',$scope.result);
  };
  
  $scope.$watch('input', function(ov,nv) {
    if (nv!==ov)
      $scope.proccess_input();
  });
});
app.controller('outputChildCtrl', function($scope, $controller) {
  
  $controller('outputCtrl',{$scope : $scope });
  $controller('parentCtrl',{$scope : $scope });
  
  
  $scope.proccess_input = function() {
    // how can i wrap a call to outputCtrl.process_input here ?
    $scope.result = $scope.processing_function($scope.result);
    console.log('outputChildCtrl processing ',$scope.result);
  };
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers