Unable to handle onbeforeunload event using Angular Service
问题 I have the following callback for my onbeforeUnload event in one of my service. In my app.run block I have: window.onbeforeunload = Services.beforeWindowClose; and this method is in a service: this.beforeWindowClose = function (event) { var currentState = $state.current.name; if (currentState !== constant.LOGOUT) { $rootScope.$broadcast("close"); if (Utilities.isSavePending) event.returnValue = constant.MSG; } } In my controllers I have : $scope.$on("close", function () { Utilities