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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top