Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngRoute not properly destructed upon $destroy of $rootScope #8295

Closed
Daanoz opened this issue Jul 22, 2014 · 4 comments
Closed

ngRoute not properly destructed upon $destroy of $rootScope #8295

Daanoz opened this issue Jul 22, 2014 · 4 comments

Comments

@Daanoz
Copy link

Daanoz commented Jul 22, 2014

In our application we use angular for all popup windows, a popup window has multlple pages (wizard-like) and are controller by ngRoute.

As the popup closes, we implicitly destruct the $rootScope:

angular.element('#modal-content').scope().$root.$destroy();

However, ngRoute still locks down the browser's hash location, forcing all window.location.hash changes to the $routeProvider.otherwise() setting.

For example, configuration:
$routeProvider
.when('/', {
...
})
.when('/page2', {
...
})
.otherwise({
redirectTo: '/'
});
After closing the popup and destroying the rootScope that configured the route, changes to window.location.hash, get reverted to '#/'.

Stepping through the code, it seems that the "$browser.startPoller" function (https://code.angularjs.org/1.2.20/angular.js line: 4431) is never properly stopped/cleared, which in turn triggers ngRoute on every hash change.

@shahata
Copy link
Contributor

shahata commented Jul 22, 2014

I believe this will be fixed by #8005

@IgorMinar
Copy link
Contributor

related to #8005

@IgorMinar IgorMinar reopened this Jul 22, 2014
@IgorMinar
Copy link
Contributor

This is a dupe of #7578 and is not ngRoute specific. and #8005 looks like the best PR candidate so far.

@Daanoz
Copy link
Author

Daanoz commented Jul 23, 2014

If anyone is looking for a work around, this might work (version 1.2.10):

            angular.element('#modal-content').injector().invoke(function ($route) {
                $route.current = false;
                $route.routes[null] = false;
            });

Although this 'works' in my case, it is no way a solution, it does not stop the $browser/$location service from polling, and overriding the hash url with the / prefix. It does stop however the redirection to the routed pages. I would definitely not recommend to use it if there is another way you can make your code working.

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

No branches or pull requests

3 participants