cgross / angular-busy

Show busy/loading indicators on any element during $http requests (or any promise).
http://cgross.github.io/angular-busy/demo
MIT License
1.44k stars 257 forks source link

Does not exit on $q.reject #98

Closed bartonsprings closed 8 years ago

bartonsprings commented 8 years ago

The promise does not return (end) on a deeper $q.reject. Maybe I am not doing this correctly. The cg-busy indicator keeps showing even when the getQuestions() promise has returned with a $q.reject. It works fine if it returns with a resolve NOT with reject. I understand that I can make this a single line $resource call but this is just representation of any other promise which may have more than one chained "then" promises. Any clue on what is going on is greatly appreciated.


` // Assign cg-busy assignment to this promise $scope.questionsPromise = getQuestions();

            // Get questions list from the backend
            function getQuestions() {
                var deferred = $q.defer();
                var errorObj, errorMsg;
                var restParams = {
                    "someId": $scope.someId,
                    "filter[IsActive][eq]": 1,
                    "sort[PriorityOrder]": "asc",
                    "limit": 500
                }
                ProjectQuestions.query(restParams).$promise
                .then(function (results, getResponseHeaders) {
                    // Done retrieving if successful
                    $scope.questions = results.Items;
                    console.log(results.Items);
                    deferred.resolve();
                }, function (err) {
                    errorMsg = "Failed retrieving list";
                    errorObj = { "status": 500, "message": errorMsg, "source": resourceTitle, "internal": err };
                    return $q.reject();
                })
                return deferred.promise;
            }

`

bartonsprings commented 8 years ago

I found the error in my code. I was not returning the promise.

ProjectQuestions.query(restParams).$promise

Should be: return ProjectQuestions.query(restParams).$promise