1

I'm using dart 1.19.1 and angular2 beta 21.
I have quite a strange problem, and I cannot find a solution.
Let's say, for example, that I have a component that groups some input elements and that is part of a list. I need to save the data changed inside the component when the user exits. I update data trough a call to a web service.
Now, I did the following:

  1. Registered to the focusout event. Forgetting the problem that focusout is not supported in all browsers and that blur does not bubble, the question is that focusout it emitted by the single input element, so, receiving such a message does not mean that the user exited the component
  2. Using ngOnDestroy. That works quite good, except when the user close the browser tab. In this case it is not called. I do not know if this is a bug or not, anyway I would like to have any ngOnInit paired by a ngOnDestroy call.
  3. Registered to tab closing. I tried to register to window.onbeforeunload event. It works in the sense that the function is called, and my code is executed, but even if the call to the web service seems to be executed, I never receive a reply (the callback is never called), and the server in some cases does not receive nothing, in others it crashes with strange errors that I still have not properly understood.

Am I doing something wrong? Probably yes.

Anyway, The solution I have adopted so far is to use onbeforeunload to alert the user to use the log off procedure, otherwise he could lose some data, but it is obviously a workaround.

Any hint?

J F
  • 1,058
  • 2
  • 10
  • 21
  • Looks like it is your case http://stackoverflow.com/a/14930010/5521491. Anyway, any kind of browser close handler it is not a good place for saving your data. – Adamovskiy Sep 26 '16 at 13:31

0 Answers0