$ ionicLoading.hide()不起作用

时间:2017-03-31 03:37:07

标签: ionic-framework

我有这个离子代码。问题是$ ionicLoading.hide();没有隐藏弹出窗口。我不能让“等待”图标消失

函数($ scope,$ q,$ state,$ rootScope,$ stateParams,$ firebaseArray,$ window,$ ionicLoading){

var palabras =  $rootScope.textAreaOfrecer.replace(/[.#$/]/g,'').toLowerCase().split(' ');

if($rootScope.flag == 1){
    return true;
}else{
    $rootScope.flag = 1;
}

console.log("0");  

$ionicLoading.show();  

setMyNewArray().then( function (){

                        console.log("3");
                        $ionicLoading.hide();
                        $rootScope.flag = 0;
                        console.log("4");
                    });       

 function setMyNewArray() {  

        var deferred = $q.defer();

          console.log("1");

          Promise.all(
                $scope.solicitudes = palabras.map(palabra => $firebaseArray(firebase.database().ref().child("solCompras").orderByChild("palabras/" +   
                                            palabra).equalTo(true) ) )
                ).then( function (){

                                   $scope.solicitudes = multiDimensionalUnique($scope.solicitudes).reduce(function(prev, curr) {

                                       return prev.concat(curr);
                                   });

                                    console.log("2");

                                    deferred.resolve();


                        });  

       return deferred.promise;


 }  


        function multiDimensionalUnique(arr) {
            var uniques = [];
            var itemsFound = {};
            for(var i = 0, l = arr.length; i < l; i++) {
                var stringified = JSON.stringify(arr[i]);
                if(itemsFound[stringified]) { continue; }
                uniques.push(arr[i]);
                itemsFound[stringified] = true;
            }
            return uniques;
        }

}

1 个答案:

答案 0 :(得分:1)

我已经更改了show loader的位置并隐藏了加载器..尝试一次

 function ($scope, $q, $state, $rootScope, $stateParams, $firebaseArray, $window, $ionicLoading) {

    var palabras =  $rootScope.textAreaOfrecer.replace(/[.#$/]/g,'').toLowerCase().split(' ');

    if($rootScope.flag == 1){
        return true;
    }else{
        $rootScope.flag = 1;
    }

    console.log("0");   

    setMyNewArray().then( function (){

                            console.log("3");

                            $rootScope.flag = 0;
                            console.log("4");
                            $ionicLoading.hide();  //use hide here
                        });       

     function setMyNewArray() { 

           $ionicLoading.show();   //use loader here. 

            var deferred = $q.defer();

              console.log("1");

              Promise.all(
                    $scope.solicitudes = palabras.map(palabra => $firebaseArray(firebase.database().ref().child("solCompras").orderByChild("palabras/" +   
                                                palabra).equalTo(true) ) )
                    ).then( function (){

                                       $scope.solicitudes = multiDimensionalUnique($scope.solicitudes).reduce(function(prev, curr) {

                                           return prev.concat(curr);
                                       });

                                        console.log("2");

                                        deferred.resolve();


                            });  

           return deferred.promise;


     }  


            function multiDimensionalUnique(arr) {
                var uniques = [];
                var itemsFound = {};
                for(var i = 0, l = arr.length; i < l; i++) {
                    var stringified = JSON.stringify(arr[i]);
                    if(itemsFound[stringified]) { continue; }
                    uniques.push(arr[i]);
                    itemsFound[stringified] = true;
                }
                return uniques;
            }
    }