2017-05-02 19 views

回答

0

創建一個新的承諾來處理時,它已經完成加載信息,所以你需要滾動到底,你的情況使用像這樣:

您.TS文件

appendRows(newData){ 
if(!newData || newData.length == 0) 
    return; 
    this.myNewPromise().then(res =>{ 
    if(res){ 
     this.content.scrollToBottom(0); 
    } 
    }) 
} 

myNewPromise =(): Promise<boolean> =>{ 
    return new Promise<boolean>(res){ 
    if(this.messages){ 
     let newArray = this.messages.concat(newData); 
     this.messages = newArray; 
     res(true); 
    }else{ 
     this.messages = newData; 
     res(false); 
    } 
    } 
} 

所以你的scrollToBottom只會在myNewPromise完成時觸發。在你的承諾中,你解決它並返回一個布爾值,所以如果有新消息,你可以調用scrollToBottom

如果您需要調用它,只需在res中傳遞true或在myNewPromise的返回中刪除if (res)

希望它有幫助。

+0

嗨,我的朋友,非常感謝你的回答。你看,問題不在Javascript方面。問題在於Angular使用ngFor來創建基於更新的「messages」屬性的視圖。所以當我們在JS端調用scrollToBottom()時,Angular沒有完成構建視圖。 –

+0

即使,我試過你的解決方案只是爲了確保,結果是一樣的:( –

+0

你脫離ionViewDidEnter?它也調用scrollToBottom –