Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

$modal cant be dismissed if state [ui-router] is changed #3694

Closed
slepkaviba opened this issue May 20, 2015 · 21 comments
Closed

$modal cant be dismissed if state [ui-router] is changed #3694

slepkaviba opened this issue May 20, 2015 · 21 comments

Comments

@slepkaviba
Copy link

Hi,

Using ui-router and $modal brings confustion when $modal inherits scope from current state controller's scope. If state is changed, modal's methods are gone, and its impossible to close it (I tried using $stateChangeStart and $destroy events, but in both - its already too late and dismiss and close have no effect).

One solution was not using inherited scopes but in case they are needed - modal stays open forever.

Br

@slepkaviba slepkaviba changed the title $modal cant be dismissed if state is changed $modal cant be dismissed if state [ui-router] is changed May 20, 2015
@chrisirhc
Copy link
Contributor

Could you create a Plunker that demonstrates this?
This sounds like usage with ui-router that's confusing rather than a bug.

@deeg
Copy link
Contributor

deeg commented May 29, 2015

Having a simmilar issue, I will try to create a plunkr.

Not sure it has to do with the state change in UI-Router, you should be able to watch for state change start and use $modalStack.dismissAll to close all open modals.

The issue I run into, is $modalStack.dismissAll will not work for all modals, specifically a modal which was passed a scope which is isolated from the rootScope. If I pass the rootScope into the same modal, dismissAll starts to work.

Any ideas?

@slepkaviba
Copy link
Author

Sorry for delay. It was exactly same issue. I keep scopes separate and if scope becomes deattached $modalStack cant access methods from it anymore (neither can we).

@rvanbaalen
Copy link
Contributor

@slepkaviba Please answer the question and provide a plunkr. Without a plunkr reproducing the problem, we won't start investigating it.

@deeg
Copy link
Contributor

deeg commented Jun 2, 2015

Creating a plunker wasn't working for me, so it must be another issue than the isolate scope. Still trying to pin it down.

Upon further investigation, I believe it has to do with the $animation service. If I change animation to false everything works fine.

When animation is on and it is not working the following callback is never called correctly:

      domEl.one('$animate:close', function closeFn() {
        $rootScope.$evalAsync(afterAnimating);
      })

@leobudima
Copy link

Agreed, came down to same conclusion, $animate:close never fires.

@deeg
Copy link
Contributor

deeg commented Jun 3, 2015

@leobudima, were you able to create a plunker showing the issue? When I tried the issue wasn't happening, which means there might be something else in my code which causes the issue.

@mikesir87
Copy link

Ok. I've got more info! It occurs when you specify the scope parameter and that scope is one taken from the current view. Makes sense though... if a ui-state transition occurs, that scope is going to die.

AND.... I made a plunkr :)

http://plnkr.co/edit/OSUSijMgWH5cNvmbSCLG

@moneytree-doug
Copy link

👍 Just more information, it doesn't happen in 0.12

@wesleycho
Copy link
Contributor

I believe this is fixed on master: http://plnkr.co/edit/N25cMelap9C718HrVqGS?p=preview

@moneytree-doug
Copy link

@wesleycho Why was this with the tag resolution: can't reproduce / no info? @mikesir87 gave a perfect example that reproduces it right there. It is not fixed in the link you provided, and if you open the example and click on "Open with the scope defined" and click "Go" then click the "Close" button, you would notice that it doesn't dismiss.

@wesleycho
Copy link
Contributor

He is using an old version - I linked an updated version without being able to see it reproduced.

@slepkaviba
Copy link
Author

@wesleycho on your plunkr bug is the same, I recorded a video with that:
angular_modal_scope

Though - as you reproduced the bug, and provided the example with broken code and latest angular - bug is totally not resolved.

@mikesir87
Copy link

@wesleycho - confirmed that bug still exists, even in the plunkr you posted

@wesleycho
Copy link
Contributor

So I think I see what is happening - essentially the $scope that the modal is using is inheriting from the current controller, so when the state change occurs, it is destroyed.

This looks like a bug.

I think an appropriate resolution in the library would be for the modal to close when this happens, as we cannot do anything about this otherwise. On the developer side, I would recommend not using a $scope that inherits from the $scope associated with a particular view that can get destroyed by a $route or $state change. This is because you run the risk of the $scope getting stranded like this. An appropriate workaround is to use $rootScope.$new(true) to create a new isolate scope that points to $rootScope as the parent instead.

@moneytree-doug
Copy link

@wesleycho Correct me if I am misunderstanding, but that PR looks like it will dismiss the modal if the route changes. That would be a new unexpected behaviour to me, because it would previously not dismiss if the navigation changes.

@wesleycho
Copy link
Contributor

The problem is, if we don't do that, it causes immense problems, including a completely broken modal due to $scope destruction.

This is the best solution we have.

@liquidpele
Copy link

I pulled version 0.14.3 and this fix is not complete because it leaves behind a trasparent div over the whole page... so the modal closes but the page is un-usable going forward.

@wesleycho
Copy link
Contributor

Please open a new issue with reproduction if this is still an issue

@jaybloke
Copy link

Experiencing a similar issue. In my particular case my modal attempts to retrieve json data via a resolve on the modal. If I get back a 401 response (unauthorised) via a response interceptor my app automatically presents a login modal - at least that's what it used to do before I moved to the latest version. With the latest version the first modal is never destroyed, and subsequent attempts to open any modal fail. Reverted back to the old version I was using before (0.13.3)... and all works good again.

@angular-ui angular-ui locked and limited conversation to collaborators Nov 10, 2015
@wesleycho
Copy link
Contributor

Locking issue due to lack of following of instructions - if there is an issue, open a new issue with reproduction, strongly preferably via Plunker.

Without a reproduction or strong specific evidence, we cannot fix any claimed bug, and the issue queue is not for technical support. Please read CONTRIBUTING.md before distracting people with notifications from commenting on a locked issue.

@wesleycho wesleycho reopened this Nov 10, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants