Hello,
want to use the Loading “http://ionicframework.com/docs/angularjs/views/loading/” overlay for an “$http.get(” call.
I have a factory to get the json data and push it to an array
.factory('NewsService', ['$http', function($http) {
...
and a factory for the loader overlay
.factory('LoaderService', function($rootScope, $ionicLoading) {
return {
show : function() {
$rootScope.loading = $ionicLoading.show({
// The text to display in the loading indicator
content: '<i class="icon ion-looping"></i> Loading',
// The animation to use
animation: 'fade-in',
// Will a dark overlay or backdrop cover the entire view
showBackdrop: true,
// The maximum width of the loading indicator
// Text will be wrapped if longer than maxWidth
maxWidth: 200,
// The delay in showing the indicator
showDelay: 10
});
},
hide : function(){
$rootScope.loading.hide();
}
}
});
Now i use the loader in the controller like:
.controller('NewsCtrl', function($scope, NewsService, LoaderService) {
LoaderService.show();
$scope.newses = NewsService.all();
LoaderService.hide();
})
But it is not the right, because it is asynchronous. The loader disables before the page complete the loading. How do i solve the problem and wait for the final loading and than use the “LoaderService.hide();” to disable the loader?