Function not returning values

Relatively new to creator, love everything so far!

I’m getting stuck on retrieving values from a function. Any help would be great!!

How to return the values from the function to the $scope.data?

Heres the call:

    $scope.loadData = function(){  
    Lesoproepensheetsu.query($scope.params).then(function(res){
                $scope.data = res;
                $scope.$broadcast('scroll.refreshComplete');
                console.log('Eindresultaat: '+$scope.data.ID);
        });
    };
    $scope.loadData();

And heres the function itself:

         query: function(params){
            var deferred = $q.defer();
            
            $http.get(lesoproepensheetsuURL+'/search?ID='+params.ID+'&limit=1').then(function(resp){
                
                if(resp.data.length > 0) ID = parseInt(resp.data[resp.data.length-1].ID);
                deferred.resolve(resp.data);
                            
                console.log('serviceresultaat: '+resp.data.ID);
                console.log(resp);
            });
            
            return deferred.promise;
        }