Doubt $ionicLoading.hide()

I’m using $http.get to pull data from a webservice and get json I do insert or update in a bank sqlite.

When calling the $http.get I start $ionicLoading.show() this closing to finish the http.get the request only would
close $ionicLoading when you finish the procedure in sqlite database. Can anybody help me ??

i think my logic can help you… first make a function for a button to call whenever it is click then show ionic loading after that as you http get request. finally use ionic hide after the function succeeded or not… just like this pseudo code:

$scope.getData = function () {

        $ionicLoading.show({
            templateUrl:"loading.html",
            animation: 'fade-in',
            showBackdrop: true,
            maxWidth: 200,
            showDelay: 0
        });

        $http.get("http://url.sample", { params: { username: $scope.username, password: $scope.password } })
             .success(function (data) {
                 $ionicLoading.hide();

                 
                 $scope.id = data.id;
                 $scope.username = data.username;
                 $scope.role = data.role;
                 $scope.date_created = data.date_created;
                 if ($scope.id == null) {
                     //An alert dialog
                     var alertPopup = $ionicPopup.alert({
                         title: 'Login Error',
                         template: 'Credentials are wrong or check your Internet Connection and try again'
                     });
                     alertPopup.then(function (res) {
                         console.log('Error or No Connection');
                     });
                 } else {
                     $state.go('pagename');
                 }
             })
             .error(function (data) {
                 //An alert dialog
                 $ionicLoading.hide();
                 var alertPopup = $ionicPopup.alert({
                     title: 'Login Error',
                     template: 'Your account is onhold, please wait for the Admin and try again later'
                 });
                 alertPopup.then(function (res) {
                     console.log('Error or No Connection');
                 });
             });
    };