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

feat(cdk/scrolling): Viewport needs asynchronous functions to set data #23715

Open
jzabinski-dolios opened this issue Oct 8, 2021 · 4 comments
Labels
area: cdk/scrolling feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@jzabinski-dolios
Copy link

Feature Description

The virtual scrolling viewport is asynchronously initialized. Normally developers can expect that when ngAfterViewInit() is called in a component's parent, the component will be ready for interaction, but the viewport is not yet ready at that point. The application needs to wait a tick so that the viewport can finish initializing before using functions like scrollToIndex. Developers should not need to know this before using the viewport.

I request that all functions requiring a fully initialized viewport be replaced with asynchronous versions that defer the execution of those functions until the viewport is finished with initialization. A viable alternative would be to provide an Observable that declares that the viewport is ready to receive commands.

Use Case

I want to be able to use the viewport in ngAfterViewInit as can normally be done with child components. See this Stackblitz.

@jzabinski-dolios jzabinski-dolios added feature This issue represents a new feature or feature request rather than a bug or bug fix needs triage This issue needs to be triaged by the team labels Oct 8, 2021
@mmalerba mmalerba added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Jan 7, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Mar 13, 2022

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@angular-robot
Copy link
Contributor

angular-robot bot commented Apr 1, 2022

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@jackalvrus
Copy link

Yes, please.

My use case is: I want to scroll to a specific point in the list on load of the component that uses the scroller.

Having to call scrollTo* from a setTimeout and hoping for the best is very hacky. Some way to know when the scroller is ready to receive scrollTo* calls would be much better.

Possibly even better for my use case would be a way to initialize the scroll position without an explicit call to scrollTo*.

@siqiluo7
Copy link

siqiluo7 commented Apr 9, 2023

Another workaround I use is to use scrolledIndexChange which emits when the index of the first element visible in the viewport changes. Therefore, when the viewport initialized, this event will be emit as well. And in ur code, you can use take(1) to only react on the viewport initialization.
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cdk/scrolling feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

6 participants