2

When calling a $mdDialog and then calling one more $mdDialog right after the first one - then this error appears 3 times in a row.

enter image description here

No I do not use $scope.apply() or $scope.$digest() anywhere in my code.

$scope.$$phase is null at the time of the error

The full code is too big to post here, and the error happens inside the $mdDialog minified functions.

Anyway this is where we call $mdDialog:

  $scope.$on('openDialog', function(event, data){

  $mdDialog

        // Open the dialog
        .show({
            template: require('./confirmDialog.html'),
            parent: angular.element(document.body),
            controller: function($scope) {
                var vm = this;
                vm.header   = data.header;
                vm.question = data.question;
                vm.cancel = function() {
                    $mdDialog.cancel();
                }
                vm.yes = function() {
                    $mdDialog.hide('yes');
                }
                vm.no = function() {
                    $mdDialog.hide('no');
                }
            },
            controllerAs: 'vm',
            clickOutsideToClose:true
        })
        // React to answer
        .then(function(modalActionResult){    
            console.log("scope phase", $scope.$$phase);      
            $scope.modalActions({'performAction': modalActionResult, 'type': data.type});
        })
        // Catch any errors
        .catch(function(){

        })
        // Close and kill listeners?
        .finally(function() {

        });

    }); 
torbenrudgaard
  • 2,375
  • 7
  • 32
  • 53
  • Looks like you have multiple event call `$on('openDialog'`)`. It might happen if you broadcast to `$parentScope` and `openDialog` event is triggered twice at the same digest cycle. Can you reproduce this issue in plunker/codepen? – Maxim Shoustin Aug 28 '17 at 06:39
  • @MaximShoustin thats exactly what I think!! But I cannot reproduce in plunker. The one dialog is in my calendar page and the next in the bookform page and even thou Im sure its closed and done it some how manage to call the second dialog on bookform before the digest cycle is finished. I just wish there were some way to kill the digest cycle? – torbenrudgaard Aug 28 '17 at 06:47
  • What will happen if you will wrap `$mdDialog.show({...})` with `$timeout(function(){ /**/ })` ? I should run every dialog in separate digest cycle – Maxim Shoustin Aug 28 '17 at 06:51
  • But im sure you need get rid to call `openDialog` twice anyways – Maxim Shoustin Aug 28 '17 at 06:53
  • Actually I have to do this - and it works perfectly - I just wanna get rid of that big flood of red errors in the console log when I do it :) Ohh and a well placed debugger; will also solve the problem - so its obviously a matter of timing... or something... . – torbenrudgaard Aug 28 '17 at 07:18
  • Do you want me to post it as answer? – Maxim Shoustin Aug 28 '17 at 07:20
  • Sure if you got a solution so we can get rid of the annoying errors, then I will be very happy and give you the answer and an upvote :-) – torbenrudgaard Aug 28 '17 at 09:23
  • You say $timeout wrapper didn't help you right? – Maxim Shoustin Aug 28 '17 at 10:04
  • I will try the timeout here later - will let you know how it goes – torbenrudgaard Aug 28 '17 at 11:14

0 Answers0