1import {..., AfterViewChecked, ElementRef, ViewChild, OnInit} from 'angular2/core'
2@Component({
3 ...
4})
5export class ChannelComponent implements OnInit, AfterViewChecked {
6 @ViewChild('scrollMe') private myScrollContainer: ElementRef;
7
8 ngOnInit() {
9 this.scrollToBottom();
10 }
11
12 ngAfterViewChecked() {
13 this.scrollToBottom();
14 }
15
16 scrollToBottom(): void {
17 try {
18 this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
19 } catch(err) { }
20 }
21}
1<div style="overflow: scroll; height: xyz;" #scrollMe [scrollTop]="scrollMe.scrollHeight">
2 <div class="..."
3 *ngFor="..."
4 ...>
5 </div>
6</div>
7