2017-05-29 82 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 
}); 
相關問題