title: Better way to refactor $scope operations like this in AngularJS?
body: <p>My coffeescript codes looks like this</p>
  
  <pre><code>.controller('SignInController',
      ($scope, CONFIG, restAuth, cookieAuth) -&gt;
          $scope.signInData = {}
          $scope.res = {}
          # TODO: Refactor this to service
  
          $scope.processRegistration = -&gt;
              console.log($scope.signInData)
              restAuth.post('signin', $scope.signInData)
              .then(((data) -&gt;
                      if data.res &gt;= 0
                          $scope.res.signInSuccess = true
                          $scope.res.msg = 'You finished login successfully.'
                          cookieAuth.setCookie(data)
                      else
                          $scope.res.signInSuccess = false
                          $scope.res.msg = 'Your login failed. (#{ data.description })'
                  ),
                  (-&gt;
                      $scope.res.signInSuccess = false
                      $scope.res.msg = 'Sorry, it seems that the server is not responding. Please try again later!')
              )
  
  
          return
  )
  
  .controller('SignUpController',
      ($scope, $http, CONFIG) -&gt;
          $scope.signUpData = {}
          $scope.res = {}
          # TODO: Refactor this to service
  
          $scope.processRegistration = -&gt;
              $http
              .post('#{ CONFIG.ROOT }/auth/signup', $scope.signUpData)
              .success (data) -&gt;
                  if data.res &gt;= 0
                      $scope.res.signUpSuccess = true
                      $scope.res.msg = 'You finished registration successfully.'
                  else
                      $scope.res.signUpSuccess = false
                      $scope.res.msg = 'Your registration failed. (#{ data.description })'
              .error(-&gt;
                  $scope.res.signUpSuccess = false
                  $scope.res.msg = 'Sorry, it seems that the server is not responding. Please try again later!'
              )
  
          return
  )
  </code></pre>
  
  <p>As can be seen, there are many operations on <code>$scope</code>, which looks a little clumsy.. Does anyone have suggestions about how to refactor this?</p>