Hi,
I have an issue with the scrollToBottom method of the ion-content.
I’m trying to develop some kind of chat, with a bottom scrolling when messages are received.
I tried to call the Content.scrollToBottom() method as soon as I push the new message in the chatMsgs (array) but the scroll seems to be called before the view is rendered.
@ViewChild(Content) content: Content;
.
.
.
this.chatMsgs.push(data);
this.content.scrollToBottom();
In fact, the item is added to ion-content but the scrollToBottom method leads to the ‘one-before-last’ message.
Setting a timeout is the only way I found to achieve the scroll to the bottom. Even though the timeout is very short (100 ms), this method seems to be a very dirty hack.
scrollToBottom(content){
setTimeout(() => content.scrollToBottom(), 100);
}
Could someone help me scrolling in a much better way ?
Here is my chat-page.html
<ion-header style="header">
<ion-toolbar>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-card *ngFor="let msg of chatMsgs">
<ion-card-header>
<ion-card-subtitle>{{msg.from}}</ion-card-subtitle>
<ion-card-title>{{msg.content}}</ion-card-title>
</ion-card-header>
</ion-card>
</ion-list>
</ion-content>
<ion-footer style="footer">
<ion-toolbar>
</ion-toolbar>
</ion-footer>
Here is my config:
ionic (Ionic CLI) : 4.3.1 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.0.0-beta.16
@angular-devkit/build-angular : 0.10.6
@angular-devkit/schematics : 7.0.6
@angular/cli : 7.0.6
@ionic/angular-toolkit : 1.2.0
Thanks in advance,
Antoine