@ViewChild(Content) - content is undefined and I can't scroll to bottom


#1

Hi,

I’ve just detected that sometimes when I add rows to my list and try to scroll to bottom using:

//@ViewChild(Content) content: Content;
...
this.content.scrollToBottom();

my content var is undefined sometimes, so I can’t scroll down.

Any help, please?

Thank you.


#2

@Corin I don’t know when you are calling the content method in your code, but did you put that call inside ngOnInit, ngOnChanges or something like that? Maybe the view was not initiated yet. Try to use only after the view was loaded (after ngAfterViewInit was called).


#3

Thank you for your help Lucas, but no I am calling it just when I enter some message in my chat. :S

Maybe I need to give enough time to the list grow?


#4

@Corin Content should be defined. Are you using @ViewChild(Content) in the same component that has the ion-content tag in the html template? (that is, it’s not a super-component nor a sub-component)


#5

Yes, in the same component and the problem is android only. :frowning: