Angular JS 服务/工厂数据无法使用 then 函数

Angular JS Service / Factory data is not working with then function

我正在编写一个调用 userAuth 服务并检查凭据的登录表单。

当我使用时,在我的用户控制器中我没有得到响应或者甚至没有执行功能。

userController.js

'use strict'; 

myApp.controller('userController',['sessionFactory','$scope', '$http','$rootScope','$state', '$stateParams','userAuth', function 
                                                            (sessionFactory,$scope,$http,$rootScope,$state, $stateParams,userAuth) {
$scope.user={email:'learner@gmail.com',password:'123456'}

$scope.sigin = function(credentials){

    console.log(userAuth.login(credentials)); //For Testing purpose only
    userAuth.login(credentials).then(function(response){
        console.log("I am inside then function");           //Not Executed
        console.log(response);                              // Not Executed
        });
console.log("I am out of then function");                   // Executed
$scope.loading = false;                                     // Executed

};


}]);

userAuth.js myApp.service('userAuth', 函数($http,$rootScope,$q){

var deferred = $q.defer();

this.login = function(credentials){
    credentials['action']='login';
    $http.post($rootScope.baseURL+'assets/api/user.php',credentials)
    .success(function(data,status,headers,config){

        deferred.resolve = "success";
        console.log(data);            //For test purpose only. Its returning data

    })
    .error(function(data,status,headers,config){

        deferred.reject = "failed";


    });

    return deferred.promise;


}



});

我错过了什么?

deferred.resolve 和 deferred.reject 是函数而不是变量,所以尝试:

deferred.resolve("success");
deferred.reject("failed");