I've been trying to replicate the loaing example on this page (Showing Spinner GIF during $http request in angular) by @punkrockpolly. But either the example is wrong or I'm not getting something.
Basically i have a directive
.directive('loading', ['$http', function ($http) {
var html = '<div class="loader" data-loading></div>';
return {
restrict: 'E',
replace: true,
template: html,
link: function (scope, element, attrs) {
console.log(element);
scope.isLoading = function () {
console.log("is loading");
return $http.pendingRequests.length > 0;
};
scope.$watch(scope.isLoading, function (value) {
console.log(value);
if (value) {
element.removeClass('ng-hide');
} else {
element.addClass('ng-hide');
}
});
}
};
}]);
That I'm trying to turn on or off based on the $http request.
Here's what I have on my HTML page
<loading></loading>
What am I missing here.