How do I broadcast from the http interceptor?
Using AngularJS 1.2
My interceptor looks like this:
$httpProvider.interceptors.push(['$q', '$log', '$rootScope',
function ($q, $log, $rootScope) {
return {
'request': function(config) {
$rootScope.$broadcast('spin');
console.info('request!');
return config || $q.when(config);
},
...
In my nav controller (which handles and binds the loader/spinner to the
view):
$rootScope.$watch('spin', function(event) {
console.info('spin');
$scope.spinner++;
});
The broadcast seems to happen only once at the end of all the responses
received, even though I can see many request! in the console log.
How must I manage my global spinner/loader?
EDIT I wish to show a loader/spinner in my navbar whenever data is being
loaded.
No comments:
Post a Comment