Using callbacks in a Restangular service I have a project built with AngularJS and using Restangular in my services to handle API requests. The problem is I haven't found a good way to test the services which I think has turned into a bit of a code smell for me. I'm using callbacks in the promise to handle pushing the data back to the controller instead of just returning the result.

Here is a simple controller and service:

myApp.controller('CustomerController', ['$scope', 'Teams', function($scope, Teams) {
    Teams.getList(function(results) {
        $scope.teams = result;
    });
}]);
myApp.factory('Teams', ['Restangular', function(Restangular) {
    var Teams = {};
    Teams.getList = function(callback) {
        Restangular.all('teams').getList().then(function(results) {
            callback(results);
        });
    };
    return Teams;
}]);


Is that really the best way to get the data back to the controller? I'm starting to feel like this isn't the correct way to do it but I haven't found another way that works.
Well, when you're already using promises you also just return that instead of using a callback.  Then you can also chain more promises at the end and add error handling.  Other than that it looks fine; I don't see what you'd really change there.

myApp.controller('CustomerController', ['$scope', 'Teams', function($scope, Teams) {
    Teams.getList().then(function(results) {
        $scope.teams = result;
    }, function(error) {
        ...
    });
}]);
myApp.factory('Teams', ['Restangular', function(Restangular) {
    var Teams = {};
    Teams.getList = function() {
        return Restangular.all('teams').getList();
    };
    return Teams;
}]);


If you want to get rid of Teams, I've seen this variant as well:

myApp.factory('Teams', ['Restangular', function(Restangular) {
    var getList = function() {
        return Restangular.all('teams').getList();
    };

    return {
        getList: getList
    };
}]);