Content.scrollToBottom


#1

Hello. I encountered a problem, please tell me how to solve:

  1. home.html:
<ion-content #myContent> 
    <ion-item *ngFor = let some of _somes> 
        .... some code .... 
    </ion-item> 
</ion-content>
  1. home.ts
@ViewChild ('myContent') content: Content; 
..... some code ..... 
getSomes() {
    this.http.post (....).subscribe((data: any) => {
        this._somes = data.somes
    }, (error: any) => {}, () => {
        this.content.scrollToBottom()
    })
}

The problem is the following:

  • On demand, the post loads an array of 94+ objects, which has about 15 properties of type String; After processing the data, I believe that ngZone changes are detected, but scrolling does not work.

More precisely, it works, but it stops at half the height of ion-content, apparently at the time the scrollToBottom function is called, the whole array does not succeed in pushing through ngZone.

Question: When, where and how do I call content.scrollToBotoom() to really get to the end of the content? (Is there an event / method that works after the end of detection of changes in ngZone?)


#2

about ngAfterViewChecked - This function is run every time after checking for changes when changes occur: when folded, deployed an element when something clicked off or clicked on the button click. In these situations, content.scrollToBottom () is not needed (because in the middle of the content there can be an ion-item that will cause any changes and push them into ngZone)


#3
@ViewChild ('myContent') content: Content; 
..... some code ..... 
getSomes() {
    this.http.post (....).subscribe((data: any) => {
        this._somes = data.somes
    }, (error: any) => {}, () => {
        setTimeout(()=>{
            this.content.scrollToBottom()
        }
    })
}

solved problem for me