Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to capture scroll position in ngOnDestroy #11003

Closed
natcohen opened this issue Aug 23, 2016 · 3 comments
Closed

Unable to capture scroll position in ngOnDestroy #11003

natcohen opened this issue Aug 23, 2016 · 3 comments

Comments

@natcohen
Copy link

natcohen commented Aug 23, 2016

I'm submitting a ...

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
When checking the scroll position in ngOnDestroy(), it always returns 0

Expected/desired behavior
Should return the scroll position

Reproduction of the problem
http://plnkr.co/edit/OCdhEonzrkpRaT8iYB0i?p=preview

Check the console for the scroll position when clicking a button and when switching to the about menu

What is the expected behavior?
Return the scroll position

What is the motivation / use case for changing the behavior?
Would like to save the scroll position before the component is destroyed

Please tell us about your environment:

  • Angular version:
    2.0.0-rc.5
  • Browser:
    Chrome 52.0.2743.116 m
  • Language:
    TypeScript
@zoechi
Copy link
Contributor

zoechi commented Aug 24, 2016

@IgorMinar
Copy link
Contributor

when ngOnDestroy is called, the underlying element is no longer part of the document, so it's scroll position was reset by the browser.

a higher level event would be better to capture the scroll position. if you are using router then you can listen via CanDeactivate and capture the position there.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants