Hiển thị các bài đăng có nhãn scroll to bottom. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn scroll to bottom. Hiển thị tất cả bài đăng

angular2 scroll to bottom (chat style)

Source: https://stackoverflow.com/questions/35232731/angular2-scroll-to-bottom-chat-style/45367387

I had the same problem, I'm using a AfterViewChecked and @ViewChild combination (Angular2 beta.3).
The Component:
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) { }                 
    }
}
The Template:
<div #scrollMe style="overflow: scroll; height: xyz;">
    <div class="..." 
        *ngFor="..."
        ...>  
    </div>
</div>
Of course this is pretty basic. The AfterViewChecked triggers every time the view was checked:
Implement this interface to get notified after every check of your component's view.
If you have an input-field for sending messages for instance this event is fired after each keyup (just to give an example). But if you save whether the user scrolled manually and then skip the scrollToBottom() you should be fine

AH00035 permission denied

  sudo chmod 751 /home/ubuntu sudo chown -R ubuntu:www-data /home/ubuntu/genealogy-giapha sudo chmod -R 750 /home/ubuntu/genealogy...