Created
September 27, 2013 19:57
-
-
Save ianjosephwilson/6734333 to your computer and use it in GitHub Desktop.
loading notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.config(function($routeProvider, $locationProvider, $httpProvider) { | |
// ... | |
$httpProvider.responseInterceptors.push(function ($q, $rootScope) { | |
return function (promise) { | |
$rootScope.$broadcast('startLoading'); | |
return promise.then(function (response) { | |
$rootScope.$broadcast('stopLoading'); | |
return response; | |
}, function (response) { | |
$rootScope.$broadcast('stopLoading'); | |
return $q.reject(response); | |
}); | |
}; | |
}); | |
}); | |
app.directive('appLoadingNotification', function () { | |
return { | |
template: '<div ng-show="isLoading()" class="alert alert-info">Loading ...</div>', | |
replace: true, | |
restrict: 'A', | |
link: function (scope) { | |
var loading = 0; | |
scope.$on('startLoading', function () { | |
loading += 1; | |
}); | |
scope.$on('stopLoading', function () { | |
loading -= 1; | |
}); | |
scope.isLoading = function () { | |
return loading > 0; | |
}; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment