Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
56
rated 0 times [  60] [ 4]  / answers: 1 / hits: 19369  / 11 Years ago, wed, september 11, 2013, 12:00:00

I'm wondering how to show a simple loader before data was loaded.
I'm using ng-grid-1.3.2
I'm googling but I didn't find any example.
Bye


More From » angularjs

 Answers
3

like Maxim Shoustin suggested you can use the angularjs-spinner from Jim Lavin which uses (deprecated) Response Interceptors.



I think it's explained best here :
http://codingsmackdown.tv/blog/2013/04/20/using-response-interceptors-to-show-and-hide-a-loading-widget-redux/



In a nutshell, in his first solution, what you have to do for your ng-grid app is:



1) Add the loading gif to your html (for loading gif look here)



<div id=loadingWidget class=row-fluid ui-corner-all style=padding: 0 .7em; loading-widget >
<div class=loadingContent>
<p>
<img alt=Loading Content src=images/ajax-loader.gif /> Loading
</p>
</div>
</div>


2) In your code as soon as you have declared your app level module add the Response Interceptors for http requests to the configuration block



var app = angular.module('myCoolGridApp', ['ngGrid']);

app.constant('_START_REQUEST_', '_START_REQUEST_');
app.constant('_END_REQUEST_', '_END_REQUEST_');
app.config(['$httpProvider', '_START_REQUEST_', '_END_REQUEST_', function ($httpProvider, _START_REQUEST_, _END_REQUEST_) {
var $http,
interceptor = /* see extra details on codingsmackdown.tv */
$httpProvider.responseInterceptors.push(interceptor);
}


3) and then add your loadingWidget directive



app.directive('loadingWidget', ['_START_REQUEST_', '_END_REQUEST_', function (_START_REQUEST_, _END_REQUEST_) {
return {
restrict: A,
link: function (scope, element) {
element.hide();
scope.$on(_START_REQUEST_, function () {element.show();});
scope.$on(_END_REQUEST_, function () {element.hide();});
}
};
}]);


See more details at codingsmackdown


[#75757] Tuesday, September 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hasanjustusf

Total Points: 76
Total Questions: 116
Total Answers: 100

Location: Virgin Islands (U.S.)
Member since Tue, Jul 7, 2020
4 Years ago
hasanjustusf questions
;