angular scroll to bottom code example
Example 1: scroll to top angular
<router-outlet (activate)="onActivate($event)"></router-outlet>
export class AppComponent {
onActivate(event) {
window.scroll(0,0);
}
}
Example 2: scoll a div to bottom in angular
import {..., AfterViewChecked, ElementRef, ViewChild, OnInit} from 'angular2/core'
@Component({
...
})
export class ChannelComponent implements OnInit, AfterViewChecked {
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
ngOnInit() {
this.scrollToBottom();
}
ngAfterViewChecked() {
this.scrollToBottom();
}
scrollToBottom(): void {
try {
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
} catch(err) { }
}
}