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.