Have you tried implementing this in your code? I've created a fiddle that shows this working.
destroy is a custom event that is fired when an element is removed from the DOM (using a jQuery function like html, remove, replaceWith, ...). Controller listens for this event and calls the destroy method.
In the example of a parent/child. When the parent's DOM element is removed, the child's is also removed so the destroy method on both controllers will be run.
If that's not the case with your code, create a fiddle and post it here.
Like I explained above and Justin mentioned, when you remove the parent DOM element from the DOM, the child is also removed. The destroy event is triggered on all of the DOM elements that were removed and the one's that have Controllers attached will have their destroy function called.
Now when you call the destroy function on a Controller, there are no events being fired, no DOM elements removed, you are simply calling a function that removes a Controller from a DOM element.
It is recommended that you override the destroy method and undo anything that you did to the DOM. While destroy is very smart, there is no way for it to track other modifications you have made unless you override it.
So you should override the destroy function to call destroy on the child controller if you want this to happen.
Here's the modified fiddle showing how things behave when you remove vs. destroy a Controller.
Leave a comment on Curtis Cummings's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic