0

I have a form page, that a user will use to insert a certain value on the database.

What I want to do is, detect if the user clicked the back button on the browser and show a modal asking if he wants to continue filling the form or really go back.

Can this be done with AngularJS?

2
  • 1
    Possible dupe of stackoverflow.com/questions/29901409/… Commented Nov 7, 2017 at 18:53
  • 1
    @james00794 State change events are deprecated, DISABLED and replaced by Transition Hooks as of version 1.0 Commented Nov 7, 2017 at 18:57

1 Answer 1

0

You can use the hook OnExit of the UI-Router. That hook is invoked when a state is being exited:

$stateProvider.state({
  name: 'your-state',
  onExit: ['MyService', function (MyService) {
    return MyService.openModal();
  }]
});

Here, on the official documentation you can find more details about how this works.

Keep rocking!

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately this won't do the trick because I have many child states that make up the form. And a parent state that directs to these child states. So if I use onExit, the popup will show everytime the user changes the "sub-form".
I understand your problem. Other option can be fire the modal when the mouse leaves the window

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.