In the .run
section of the main module of my application, I have an event handler for the $locationChangeStart
event. I want to use this in order to confirm discarding unsaved changes. The problem is that I need a reference to the $scope
in order to perform these checks.
I tried adding that reference as I added the one for the $rootScope
, but I get an error Uncaught Error: Unknown provider: $scopeProvider <- $scope
.
How should I proceed to this? I am open for alternatives.
.run(['$rootScope', '$location', function ($rootScope, $location) {
$rootScope.$on("$locationChangeStart", function (event, next, current) {
if ($scope.unsavedChanges && !confirm('Unsaved changes') {
event.preventDefault();
}
});
}