Angular 添加一个按钮以滚动到顶部

Angular 添加一个按钮以滚动到顶部,angular,ionic2,Angular,Ionic2,我试图检测用户何时向下滚动…并在单击时显示滚动到顶部的按钮 我没有创建指令,我发现很难理解,所以我使用的是内容 单击按钮时,我已成功滚动到顶部 .ts 但是我不知道如何显示和隐藏按钮。。。。当前它显示在构造函数this.showButton=true中 我想在scrollTop更改时显示该按钮您可以尝试使用ionScrollStart事件或ionScroll事件 在html中 <ion-content (ionScrollStart)="showScrollButton()"> 它

我试图检测用户何时向下滚动…并在单击时显示滚动到顶部的按钮 我没有创建指令,我发现很难理解,所以我使用的是
内容

单击按钮时,我已成功滚动到顶部

.ts

但是我不知道如何显示和隐藏按钮。。。。当前它显示在构造函数
this.showButton=true中
我想在
scrollTop
更改时显示该按钮

您可以尝试使用
ionScrollStart
事件或
ionScroll
事件

在html中

<ion-content (ionScrollStart)="showScrollButton()">

它不起作用……但我已经解决了这个问题ngOnInit(){this.ionScroll=this.myElement.nativeElement.getElementsByClassName('scroll-content')[0];this.ionScroll.addEventListener('scroll',()=>{if(this.ionScroll.scrollTop>0){this.showButton=true;}else{this.showButton=false;}}```
<ion-content (ionScrollStart)="showScrollButton()">
showScrollButton(){
  this.showButton=true;
}