【发布时间】:2017-08-14 14:40:25
【问题描述】:
我写了这段代码,用于在滚动超过 500px 后显示按钮,但“showButton”没有获得新值。
<ion-content (ionScroll)="onScroll($event)">
<button *ngIf="showButton">Scroll Top</button>
</ion-content>
my.ts 文件:
showButton= false;
onScroll($event) {
if ($event.scrollTop > 500) {
console.log(this.showButton);
this.showButton= true;
}
}
这个console.log显示“showButton”的变化,但在html中它没有变化。
“showButton”第一次获取值“false”,但是当值更改为“true”时它不能听变化,我该如何解决这个问题?
【问题讨论】:
-
感谢@JGFMK,但我没有找到解决方案。
-
试试这个
-
我认为 showbutton 不是 boolean 类型,尝试使用数字,showButton:number= 0;并在滚动功能 this.showButton= 1;
-
如果删除 ngIf,你的按钮会显示吗?
标签: ionic-framework ionic2 ionic3