2017-05-29 53 views
0

我更新了Angular到版本1.6.4。 所以我不得不更新.success.error.then.getAll(...)。然后不是函数

现在我得到以下错误:

TypeError: .getAll(...).then is not a function

的问题是这里的服务:

function getAll(page, size) { 
    return $http.get(baseUrl + '/jobprofiles?page='+page+'&size='+size, {timeout: 5000}).then(function (response) { 
     data = response; 
    }), (function(response) { 
     alertService.setAlert({'message': 'jobmatch.server.unavailable', 'classified': 'danger', 'lives':1}); 
    }); 
    } 

这里是控制器:

if($cookies.get("authenticated")=='true'){ 
    //get a list of all candidateprofiles with the use of a page and a size 
    candidateprofilesService.getAll($scope.page, $scope.size).then(function() { 
     $scope.data = candidateprofilesService.getData()._embedded.candidateprofiles; 
     candidateprofilesService.getAll($scope.page, $scope.size+10).then(function() { 
     if(candidateprofilesService.getData()._embedded.candidateprofiles.length > $scope.data.length){ 
      $scope.moreData = true; 
     } 
     else { 
      $scope.moreData = false; 
     } 
     }) 
    }); 
    } 
+0

你在你的candidateprofilesService暴露GETALL? –

回答

0

Y我们的功能应该是这样的,

function getAll(page, size) { 
    return $http.get(baseUrl + '/jobprofiles?page='+page+'&size='+size, {timeout: 5000}).then(function (response) { 
     return data = response; 
    }, function(response) { 
     alertService.setAlert({'message': 'jobmatch.server.unavailable', 'classified': 'danger', 'lives':1}); 
    }); 
} 
+0

你能通过这个链接找到你的问题吗? https://docs.angularjs.org/api/ng/service/$http –

1

您服务代码应该是这样的:

myApp.service('candidateprofilesService', function($http) { 
    this.getAll = function (page, size) { 
     // just return the promise , don't evaluate here 
     return $http.get(baseUrl + '/jobprofiles?page='+page+'&size='+size, {timeout: 5000}); 
    }  

    this.getData = function(){ 
     // your getData() method body, also just return the promise. 
    } 
}); 

然后在注射服务后您的控制器,

candidateprofilesService.getAll($scope.page, $scope.size).then(function(response){ 
     //Evaluate promise here and handle the response 
    }, function(error){ 
     //handle error 
}); 
相关问题