Hi all,
I need your help fixing my scrollToBottom();
I’ve recently followed Simon’s tutorial:
His tutorial teaches us how to make a real-time chat app using Socket.io, Ionic 2+ and Angular 2.
I followed the tutorial completely and everything is perfect; but I tried adding a ViewChild for (‘content’);
that way I’ll be able to automatically scroll down (it works) but my console.log(); and Ionic keep returning the following errors.
Ionic Error:
Runtime Error Cannot read property 'scrollToBottom' of null
Ionic Serve -lc Error:
[18:30:53] console.error: ERROR [object Object]
Implimentation of scrollToBottom();
scrollToBottom() fix source:
javascript - ionic 2 + angular 2 : auto scroll to bottom of list / page / chat - Stack Overflow
Chatmessages.html:
<ion-content #content>
<--- Source requests #content be added to ion-content --->
</ion-content>
I have these references in my Chatmessages.ts:
import { Component, ViewChild } from '@angular/core';
I’ve tried doing it in the Component like this:
@Component({
selector: 'page-chatmessages',
templateUrl: 'chatmessages.html',
queries: {
content: new ViewChild('content')
}
})
That didn’t work so I’m trying this:
@ViewChild(Content) content: Content;
That doesn’t work either…
//scrolls to bottom whenever the page has loaded
ionViewDidEnter() : void{
//if(this.content._scroll) this.content.scrollToBottom(0);
this.content.scrollToBottom(300);//300ms animation speed
}
scrollToBottom() {
this.content.scrollToBottom();
}
In my getMessages(); and sendMessage(); I scrollToBottom() like this:
this.content.scrollToBottom(300);
Thanks!
Regards,
Neonic1