LoaderService: how to use it

Hello
I use the LoaderService in my project, but I’m not sure I use it as it was…
First I created a LoaderService service:

.factory('LoaderService', function ($rootScope, $ionicLoading) {
// Trigger the loading indicator
return {
    show: function () { //code from the ionic framework doc
        // Show the loading overlay and text
        $rootScope.loading = $ionicLoading.show({
            // The text to display in the loading indicator
            content: '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: 0
        });
    },
    hide: function () {
        $ionicLoading.hide();
    }
}

And when I want to make a request, I write:

var ret = myConnection.doRequest(username, password, url, LoaderService);
    ret.success(function (response) {
        $state.go('successstate');
    })
    .error(function (response, status) {
        console.log('rep ', response);
        console.log('sta ', status);
    })
    .then(function(){
        LoaderService.hide();
    });

In the doRequest() service I do a loader.show() and I return the $http promise

Now 2 questions:

  • When I click on the button to launch the http request, the icon loader doesn’t appear immediately, it takes 0.5 to 1 second to appear… Why ? how to remove this delay ?
  • if the promise returns an error, I can see it in the console, but the loader icon doesn’t disappear, and it rounds again and again… How to fix that ?
    Thank you for your answer,
    I’m a newbie in ionic and angular, but I love them ! :smile: