"closeDeferred is null" and multiple instances
opened this issue · comments
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!
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.