Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs http post回调不工作_Angularjs_Http_Angular Services - Fatal编程技术网

Angularjs http post回调不工作

Angularjs http post回调不工作,angularjs,http,angular-services,Angularjs,Http,Angular Services,我试图从angular服务获取回调,但回调函数不起作用 这是我的控制器代码:- $scope.uu = "hello" // this i just make for test $scope.login = function(user){ //console.log(user) AuthenticationService.Login(user.username,user.password).success(function(data){ console.log(

我试图从angular服务获取回调,但回调函数不起作用

这是我的控制器代码:-

$scope.uu = "hello"  // this i just make for test
$scope.login = function(user){
    //console.log(user)
    AuthenticationService.Login(user.username,user.password).success(function(data){
        console.log(data);
        $scope.uu = data;
    })
}
我的服务代码是:-

    mainApp.service('AuthenticationService',function($http,$cookieStore,$rootScope){
    var service = {};
    service.Login = function (username, password, callback) {

            $http({
        method: "POST",
        //headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        url: 'users/authenticate',
        data: {email: username,password:password}
    })
    .success(callback);
        };
        return service;
});
我在控制台中都没有得到响应。范围都没有改变。 我曾提及这个问题,但答案对我来说并不适用。

如果您正在编写服务,您的代码应该如下所示:

mainApp.service('AuthenticationService',函数($http、$cookieStore、$rootScope){
this.Login=函数(用户名、密码、回调){
$http({
方法:“张贴”,
//标题:{'Content-Type':'application/x-www-form-urlencoded'},
url:“用户/身份验证”,
数据:{电子邮件:用户名,密码:密码}
})
.成功(回拨);
};

});检查您在调用API时遇到的错误。我正在从API获得正确的响应。api正在响应。只有回调不起作用,即使我编写了console.log('test'),在controllercallback中也不起作用。callback是您使用的函数或参数?请参阅上面的代码