Skip to content

Instantly share code, notes, and snippets.

@mtnoronha
Created April 28, 2017 19:40
Show Gist options
  • Save mtnoronha/e78eba6b610b71f1e72424ed21722be1 to your computer and use it in GitHub Desktop.
Save mtnoronha/e78eba6b610b71f1e72424ed21722be1 to your computer and use it in GitHub Desktop.
Ionic - Scroll to Bottom issue
<ion-header>
<ion-navbar>
<ion-title>
Test
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item text-wrap *ngFor="let message of messages" >
<h2>{{message}}</h2>
</ion-item>
</ion-list>
</ion-content>
import { Component, ViewChild } from '@angular/core';
import { Content, NavController, NavParams } from 'ionic-angular';
@Component({
selector: 'messages',
templateUrl: 'messages.html'
})
export class Messages {
messages: any;
intervalId: number = 0;
@ViewChild(Content) content: Content;
ionViewDidEnter() {
this.content.scrollToBottom(0);
}
ionViewWillUnload(){
clearInterval(this.intervalId);
}
constructor() {
this.messages = [12,44,23,53,563,234,1,21,23,5234,56213,13,34,245,123,12,123,123,12,123,123,123,13,5,
213123,123,5,123,5,123,123,34,123,5,13,34,45,123];
this.intervalId = setInterval( () => {
this.fetchMessages();
}, 1000);
}
appendRows(newData){
if(!newData || newData.length == 0)
return;
if(this.messages){
let newArray = this.messages.concat(newData);
this.messages = newArray;
}else{
this.messages = newData;
}
this.content.scrollToBottom(0);
}
fetchMessages(){
this.appendRows(this.randomNumbers());
}
randomNumbers(){
return Math.random();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment