Get parent Content element from child


I’m trying to scroll the content based from a component which is a child of the actual content component.

     <custom-component with scroll logic />

I’m not sure how to get the Content to use getScrollElement()

Thanks in advance,
Robin Hinderiks

Can’t you make that happen with CSS?
set a height and use overflow-y: auto|scroll

My explaining is a bit crappy i see.

<custom-component contains a list with many items based on date. Some in the past some in the future. I want the view to start at today. which is a variable position on this list. So i need to scroll to that part of the page and to do this i need Content object. Normally i would use @ViewChild(Content) content: Content; to get this but since ion-content is the parent i cannot do that.

However i fixed it right now by passing the content to the custom component with a input parameter.

Alright, I think I understand now. Very simply said you have a big list and you want the page to automaticly scroll to a specific item when the page loads. Not 100% sure but you could give today an ID and use # to get there. Another option is to calculate the position of the item and scroll to it using typescript.

Yeah the problem is not the logic to scroll down or to determine the position where to scroll. The problem is getting access to which had the scroll element on which you can execute the scrollTo function. However as previously stated i found a way to make it work.

Thanks for the help though, sometimes a “rubber duck” ( is enough to come to a solution

1 Like