material icon indicating copy to clipboard operation
material copied to clipboard

md-dialog still does not work with $q.all()

Open philippbussche opened this issue 10 years ago • 3 comments

Hi, I am trying to show a dialog with a progress circle while data loads and automatically hide the dialog again after data has arrived. I found the solution of a gentleman who reported the usage of $q only to be working in angular material 0.10.x and below (https://github.com/angular/material/issues/3919). What he built would be exactly what I am after. The issue is marked as fixed but when I tried with a recent version then this still does not seem to work. Please see my codepen: http://codepen.io/anon/pen/EPwpKe - the dialog never closes. Are there any other ways how to open and close a dialog after data loading has finished ? Thanks Philipp.

philippbussche avatar Jan 17 '16 00:01 philippbussche

My guess is that it has something to do with the promises resolving in the same digest cycle as opening the dialog. I modified your codepen by wrapping the promises in a timeout and it seems to work as you want it to.

Emeegeemee avatar Jan 17 '16 05:01 Emeegeemee

Thanks @Emeegeemee. I took your changes over into my app and it is now working as I am expecting it. I am pasting my Controller source below if anybody else ever needs something similar. As you can see I am querying data via a factory and as soon as thats there I am closing my dialog again. I am still new to Angular so one of the things I currently dont yet understand is why I have to specify the promise I get back from the factory call with $promise in my return function as this is different in the codepens but if I don't do that it just won't work meaning that the Dialog hide is executed immedeatly. Thanks again for your help on this !

    myControllers.controller('ResultsCtrl', ['$scope', 'DialogFactory', '$q', '$timeout', 'Cities',
    function ($scope, DialogFactory, $q, $timeout, Cities) {

    DialogFactory.show("Loading cities...");
    $q.all([fetchCities()]).
         then(function(result) {
            DialogFactory.hide();
    });

    function fetchCities() {
        $scope.cities = Cities.query();
        return $timeout(function() {return $scope.cities.$promise;});
    }

    }]);

philippbussche avatar Jan 17 '16 12:01 philippbussche

This issue is closed as part of our deprecation effort. For details, see our post Spring Cleaning 2016.

ThomasBurleson avatar Apr 28 '16 19:04 ThomasBurleson