I recently came across a new approach while reading 'Mean Machine'.
Typically, I have always been taught to return a promise from a service to the controller and then handle it using .success
or .then
.
In this case, the author is directly returning the data obtained from the promise. Is this method commonly used? Is it considered best 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;
});
};
...