Remove modal from dom

hey everybody,

i know this topic is not new but i still have a problem to completely remove the opened modal from dom. if i change to a complete other side it does but if i want to close the modal i currently have open without changing somewhere else in the app it just sets it to hide and it seems the scope is still active. how can i destroy or remove the modal and the scope on the current view without changing somewhere else?

thanks in advance

You need to remove it when you leave the current controller:

$scope.$on('$stateChangeStart', function(){
  $scope.modal.remove();
});

See : Modals Persist Between States & https://github.com/driftyco/ionic/issues/602

2 Likes

Yes i know but i need to stay in the same controller. Is this possible?

Instead of on $stateChangeStart, you could call $scope.modal.remove() on a click event, for example.

(Just be sure to have the modal hidden before doing that, not really sure what happens when you call modal.remove() if it is currently shown)

The interesting thing is that i am doing that and it is only on state hide. If i change to a different controller it gets removed from the dom. I dont know why its not working. It is on a button click. Mmmh… Do you have an example on that?

Many thanks

@hillbm I think that I know where is problem. you try to remove modal with modal.hide event which is described in docs for $ionicModal service but this type of event is never broadcasted, you have to use modal.hidden

hey,

$scope.modal.hidden() is not working. are you sure this is how the function is called? would be very much appreciated if someone could help me out to completely remove the modal from dom.

many thanks

I mean about event, not method.

But forgot about it :wink: I think that here is example which you’re looking for:

3 Likes

hey,

thanks for the example. i will take a look later this day. i am currently not in front my code

many thanks,
michael

and it works like a charm. thank you very much

Hi Calendee,

I’m a starter about whole this(AngularJs, Web). One silly question, how can I check the parent scope members of the modal in the chrome debug panel? Which properties should I look into? I found a modelEl and I saw the innerText containing previous DOM, but how can I know all members of the parent scope?

Thanks in advance.