I encountered this pattern in the book 'Mean Machine'.
Until now, I thought you always return a promise from a service (to a controller), then you deal with .success
or .then
in your controller.
Here, the author is returning the returned data from the promise.
Is this common? Is it recommended practice?
.factory('Auth', function($http, $q, AuthToken) {
var authFactory = {};
authFactory.login = function(username, password) {
return
$http
.post('/api/authenticate', {
username: username,
password: password
})
.success(function(data) {
AuthToken.setToken(data.token);
return data;
});
};
...