Currently, I am utilizing Angular 1.5 along with ui-router. My goal is to identify when a user exits a route. The code snippet I have at the moment looks like this:
$scope.$on("$stateChangeSuccess", function () {
if (!$scope.flag) {
//...
$scope.do_work(reason);
}
});
Unfortunately, this approach is not entirely effective because upon navigation to the said route, $scope.flag
is already set to false
, causing the function to execute incorrectly. Is there a conventional method to trigger a function only when a user leaves a specific route and not when they enter it?