Ionic 2在页面打开时向下滚动页面

问题描述:

我在做一个聊天应用程序。当我打开这个聊天应用程序时,我希望页面滑落。 当框处于焦点时,页面滑落。但是页面在第一次打开时不会滑落。我能做什么 ? Chat Page Picture 我的密码;Ionic 2在页面打开时向下滚动页面

ionViewDidEnter() { 
 
    this.chat(); 
 
} 
 
scrollToBottom() { 
 
    if (this.content.scrollToBottom) { 
 
    this.content.scrollToBottom(); 
 
    } 
 
} 
 
onFocus() { 
 
    this.content.resize(); 
 
    this.scrollToBottom(); 
 
    this.keyboard.show(); 
 
}

+0

@suraj欧凯,我加入到答案。谢谢 – Degisim

我从来没有使用这个属性还,但根据the docs

Attr    Type  Details 
------------------------------------------------------------------------------- 
scrollDownOnLoad boolean  If true, the content will scroll down on load. 

所以你可以做这样的:

<ion-content scrollDownOnLoad="true"> 
    <!-- ... --> 
</ion-content> 

我解决了这个问题 我叫下来滚动功能HTML

<ion-content no-padding> 
 
    <div class="message-wrap" > 
 
     <div *ngFor="let msg of gelenMesajlar; let i = index" class="message" [class.left]=" msg.GONDEREN === 'F' " [class.right]=" msg.GONDEREN === 'C' "> 
 
      <div class="msg-detail"> 
 
       <div class="msg-content"> 
 
        <span class="triangle"></span> 
 
        <span [style.font-size]="'10px'" *ngIf="msg.SIPARISID" [style.text-decoration]="'underline'">Konu #{{ msg.SIPARISID }} numaralı sipariş</span> 
 
        <p class="line-breaker">{{msg.MESAJ}}</p> 
 
        <span *ngIf="msg.SIPARISID" [style.font-size]="'12px'" (tap)="siparisGoruntule(msg.RESIMID, msg.SIPARISDURUMU, msg.SIPARISID)" [style.text-decoration]="'underline'">Siparişi Görüntüle</span> 
 
       </div> 
 

 
      </div> 
 
     </div> 
 
     {{ scrollToBottom() }} <!-- Here it is--> 
 
    </div> 
 
</ion-content>

+1

这个工作是否适合你?根据我的经验,当所有消息完全呈现时,应该调用'scrollToBottom'函数。有可能会延迟加载消息,在这种情况下,将在呈现消息之前运行'scrollToBottom'。 – Ari

+1

当然,我还有一个问题。有了这段代码,当我加载消息,然后向上滑动页面时,它再次将我调低。 @Ari – Degisim

+0

@Degisim你试过我的答案吗? (我真的很好奇,因为它是来自内容组件的一个相对较新的属性) – sebaferreras