Question

When i setup a routeprovider that contains a named group via .when('/search/:searchString', { when the page is loaded for each different :searchString it loads a new instance of the controller assigned.

This causes me a problem when i have a $rootScope.$on('searchUpdated', becuase it reacts to the broadcast message on every instance of the controller.

Is there a way to make it only load one controller and use the same controller for each request, if not is there a way to destroy the controller when the page has left.

Was it helpful?

Solution

For anyone facing a similar issue:

The controller is destroyed, but listeners registered on the $rootScope still exist, since the $rootScope is never destroyed.

The problem seems to be your registering a listener on the $rootScope from every controller instance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top