Javascript AngularJs承诺返回未定义

Javascript AngularJs承诺返回未定义,javascript,angularjs,promise,angular-promise,Javascript,Angularjs,Promise,Angular Promise,我正在尝试从AuthLoginController控制器使用AuthService工厂的登录功能。问题是,当使用错误的电子邮件和密码执行User.login函数时,console.log()返回false,这正是我想要的。但是当我使用正确的电子邮件和密码时,我会得到一个 Error: response is not defined 我不明白这一点,因为函数(error){}一切正常,但函数(success){}一切正常,即使它们都是异步调用的结果 angular .module('ap

我正在尝试从AuthLoginController控制器使用AuthService工厂的登录功能。问题是,当使用错误的电子邮件和密码执行User.login函数时,console.log()返回false,这正是我想要的。但是当我使用正确的电子邮件和密码时,我会得到一个

Error: response is not defined
我不明白这一点,因为函数(error){}一切正常,但函数(success){}一切正常,即使它们都是异步调用的结果

angular
    .module('app')
      .factory('AuthService', ['Member', '$q', '$rootScope', '$state', function(
      User, $q, $rootScope, $state) {
    function login(email, password) {
  return User
    .login({email: email, password: password})
    .$promise
    .then(function(success) {
      $rootScope.currentUser = {
        id: response.user.id,
        tokenId: response.id,
        email: email,
        firstname: response.user.firstname,
        lastname: response.user.lastname
      };
      return true;
    },
    function(error) {
      return false;
    }
    );
}   return {
      login: login
    };
    }]);
这是我的AuthLoginController控制器

angular
  .module('app')
  .controller('AuthLoginController', ['$scope', 'AuthService', '$state',
      function($scope, AuthService, $state) {
    $scope.user = {
      email: 'test1@test.com',
      password: 'test1'
    };

    $scope.login = function() {
      AuthService.login($scope.user.email, $scope.user.password)
        .then(function(response) {
          console.log(response);
            return;
          }
          //go to the default state after login
          $state.go('test');
        });
    };
  }]);
如何从AuthLoginController中检索true? 谢谢 (对不起,我的英语不好)


响应变量未在“success”回调中定义。应该改用“Success”参数变量,或者应该将其重命名为response-maybly。

您不需要返回一个使用
的承诺吗?
?我不知道。我在和AngularJs斗争。我读到调用承诺的then方法会返回一个新的派生承诺,但我不知道应该使用哪种方法。我为自己感到惭愧我读了太多的代码,以至于我失明了。这个错误太愚蠢了。谢谢你,伙计!
.then(function(success) {
      $rootScope.currentUser = {
        id: **response**.user.id,
        tokenId: **response**.id,
        email: email,
        firstname: **response**.user.firstname,
        lastname: **response**.user.lastname
      };
      return true;
    },