(function() { "use strict"; angular .module("app") .directive("appPreloader", preloaderDirective); function preloaderDirective() { return { restrict: "E", replace: true, controller: preloaderController, controllerAs: "preloaderController", templateUrl: "directives/site-preloader/loaderDirectiveTemplate.html" }; } function preloaderController($rootScope, $http) { var preloaderController = this; $rootScope.$watchCollection(getPendingRequests, function (newValue, oldValue) { if (newValue === oldValue) { return; } preloaderController.showPreloader = newValue.length > 0; }); function getPendingRequests() { return $http.pendingRequests; } } // IoC container. preloaderController.$inject = ["$rootScope", "$http"]; })();