title: Sharing code/method/function between AngularJS controllers
body: <p>I have searched around. People talked mostly about sharing data between controllers using factory. But in my case I would like to share code logic between controllers.</p>
  
  <pre><code>$scope.updatePost = function(){
    $http.get(sprintf("/posts/%s.json", post.id)).
    success(function(data, status, headers, config) {
      $scope.post = data;
    })
  };
  
  $scope.postComment = function(){
    if(!$scope.post.logged){
      window.location.href = "/users/sign_in";
    }
  
    var data = { post_id: $scope.post.id, content: $scope.content };
    $http.post("/comments", data).
    success(function(data, status, headers, config) {
      $scope.comment_error_messages = [];
      $scope.updatePost();
    }).error(function(data, status, headers, config) {
      $scope.comment_error_messages = data.errors;
   });
  }; 
  </code></pre>
  
  <p>I would like to share these two methods in two controllers. And how do I pass in the <code>$scope</code> from two different controller to my share methods?</p>
  
  <p>Thanks for any help.</p>