I am trying to implement loading wheel directive when we make ajax call so during the response time i want to display loading wheen, With below code i do not see any error neither the loading wheel.
Is there any better way to implement loading wheel using angularJs ?
or
What is implemented wrong in below code ?
main.html
<loading></loading>
<ul style="list-style: none;">
<li ng-repeat="message in event | limitTo:1000" ng-class="{lastItem: $last}"><span>{{message.value}}</span></li>
</ul>
loading.js
angular.module('App', [])
.directive('loading', function () {
return {
restrict: 'E',
replace:true,
template: '<div class="loading"><img src="http://www.nasa.gov/multimedia/videogallery/ajax-loader.gif" width="20" height="20" />LOADING...</div>',
link: function (scope, element, attr) {
scope.$watch('loading', function (val) {
if (val)
$(element).show();
else
$(element).hide();
});
}
}
})
ctrl.js
$scope.searchServerFile = function() {
console.log($scope.vm.search);
if ($scope.vm.search === undefined || $scope.vm.search === null) {
toastr.warning('A search keyword must only contain a-z, A-Z, 0-9, or space characters.');
} else {
$scope.loading = true;
searchFactory.getServerSearch($scope.vm.search, searchEnv).then(function(response) {
$scope.modalInstance.rendered.then(function() {
$rootScope.$broadcast('displaySearchResults', {
messageObj: response.data
});
$scope.loading = false;
});
}
}