I've been trying to figure out how to detect when leaving a view so I can run a bit of cleanup on the $scope. I found $ionicView (which I prefer over the use of the UI-Routers transition start and end) and tried it out in my child controller:
// When placed in child view doesn't fire, but works when dropped in parent
$scope.$on("$ionicView.leave", function (event, data) {
$ionicListDelegate.closeOptionButtons();
});
But nothing happens. So after some reading I found leave only fires on the parent $scope so I moved it up to the parent and injected the $ionicListDelegate and it works, buuut (and now my question) I really feel there has to be a better way to do this. Since my views are cached using $destroy won't work. Does anyone know of another way that I can do this? Or is having this almost global list closing event invoked on the parent not such a bad approach since lists are used a lot in my application?