title: TypeError: success is not a function
body: <p>Can somebody help me to get this fixed.
  In fact I'm trying to register a new user and before creating a new one I have to check if the username exists or not. below is the factory used for that.</p>
  
  <pre><code>.factory('accountService', function($resource, sessionService) {
      var service = {};
      service.register = function(account, success, failure) {
          if (success (service.userExists(account))){
              failure();
          } else {
              var Account = $resource("/Test/rest/account/student");
              Account.save({}, account, success, failure);
          }            
      };
  
      service.userExists = function(account, success, failure) {
          var Account = $resource("/Test/rest/account");
          var data = Account.get({
                  username : account.username,
                  password : account.password
              }, function() {
                  var accounts = data.username;
                  if (accounts &amp;&amp; accounts.length !== 0) {
                      service.data = data;
                      success(account);
                  } else {
                      failure();
                  }
              }, failure);
      };
  
      service.getuser = function() {
          return service.data;
      };
  
      return service;
  })
  </code></pre>
  
  <p>but when I run it, i get this error message: </p>
  
  <blockquote>
    <p>TypeError: success is not a function</p>
  </blockquote>
  
  <p>below is the controller that uses this factory</p>
  
  <pre><code>.controller(
              "RegisterController",
              function($scope, sessionService, $state, accountService) {
                  $scope.register = function() {
                      accountService.register($scope.account, function(
                              returnedata) {
                          sessionService.login($scope.account).then(
                                  function() {
                                      $state.go("home");
                                  });
                      }, function() {
                          $scope.registererror = function() {
                          }
                      });
                  };
              })
  </code></pre>