How is the angular way to show visual feedback to the user that the appp is waiting for an answer from the server?
Currently i have factory with following code
app.factory('MyAppFact', ['$http', '$q',
function($http, $q) {
function _success(data, status) {
document.body.classList.remove('waitserver')
if (data.status == 'OK') {
this.resolve(data);
} else {
this.reject(data);
}
}
function _error(data, status) {
document.body.classList.remove('waitserver')
this.reject(status})
}
return {
changeLocale: function(locale){
var d = $q.defer();
document.body.classList.add('waitserver');
$http.get('/changeLocale/'+locale).success(_success.bind(d),
_error.bind(d));
return d.promise;
},
login: function(uname, passwd, keep) {
var d = $q.defer();
document.body.classList.add('waitserver');
$http.post('/login', {uname:uname, passwd:passwd, keep:keep}
).success(_success.bind(d), _error.bind(d));
return deferred.promise;
},
register: function(user) {
var d = $q.defer();
document.body.classList.add('waitserver');
$http.post('/register', {user:user}).success(_success.bind(d),
_error.bind(d));
return deferred.promise;
},
...
}
}]);
Although this code works, I am adding a css class in to the document body, while according to the angularjs docs, I am not supposed to change the DOM in a factory method, thereby violating the clear separation of the MVC
But I don't see how I can accomplish the separation in this case.