2017-05-29 9 views
0

Angularをバージョン1.6.4にアップデートしました。.getAll(...)。thenは関数ではありません。

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}); 
    }); 
    } 

はコントローラです:

は、だから私は今、私は次のエラーを取得する .success.error

.thenへを更新しました
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 
}); 
関連する問題