Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"closeDeferred is null" and multiple instances #184

Open
ghost opened this issue Nov 10, 2016 · 1 comment
Open

"closeDeferred is null" and multiple instances #184

ghost opened this issue Nov 10, 2016 · 1 comment

Comments

@ghost
Copy link

ghost commented Nov 10, 2016

Hi!

I ran into a problem when trying to close a modal by a $rootScope watch.

This is my controller for the modal I want to close:

app.controller('PlaylistModalController', function($scope, $rootScope, ModalService, close, playlist)
{
  $scope.playlist = playlist;
  $scope.close = close;

  $scope.queueSong = function(song)
  {
    ModalService.showModal({
      templateUrl: "templates/modals/confirm_queue.html",
      controller: "ConfirmQueueController",
      inputs: {
        song: song
      }
    });
  }

  $rootScope.$on("idleEnter", function()
  {
    console.log(close)
    $scope.close();
  });
});

The modal closes on the 'idleEnter' event and doesn't produce an error and if it's the first time the event is fired. But when I re-open the model and the event is fired again it produces this error:

Error: closeDeferred is null
cleanUpClose@[...]/angular-modal-service.js:179:14
close/<@[...]/angular-modal-service.js:133:18
timeout/timeoutId<@[...]/angular.js:19612:28
completeOutstandingRequest@[...]/angular.js:5964:7
Browser/self.defer/timeoutId<@[...]/angular.js:6243:7

I also mentioned that the close function is printed out as often as I opened the modal before. It seems that the modal scope is not 'cleared' properly...?!
Note: the 'queueSong' function doesn't have to be called to reproduce this problem.

This is the code I use to create the modal:

 $scope.openPlaylist = function(playlist)
  {
    ModalService.showModal({
      templateUrl: "templates/modals/playlist.html",
      controller: "PlaylistModalController",
      inputs: {
        playlist: playlist
      }
    });
  };

Can you tell me where the problem is? Am I doing something wrong or is this a bug?
Thanks!

@justindmyers
Copy link

I know this issue is pretty old but I had the same issue.

What's happening is that you're using $rootScope.$on instead of $scope.$on. The $on handler is getting added to $rootScope every time you open the modal, causing it to fire multiple times.

Simply change it to $scope.$on and you should be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant