Angular.js service for onBeforeUnload