Within the .run
segment of the primary module in my application, there is an event handler designated for the $locationChangeStart
event. Its purpose is to verify the abandonment of any unsaved modifications. The setback lies in the necessity of having a connection to the $scope
to carry out these inspections.
Despite my efforts to append this reference alongside the one for $rootScope
, I encountered an error message that reads as follows:
Uncaught Error: Unknown provider: $scopeProvider <- $scope
.
Now, I am seeking guidance on how to navigate this issue. Your suggestions are welcome.
.run(['$rootScope', '$location', function ($rootScope, $location) {
$rootScope.$on("$locationChangeStart", function (event, next, current) {
if ($scope.unsavedChanges && !confirm('Unsaved changes')) {
event.preventDefault();
}
});
}