【发布时间】:2018-10-05 15:02:00
【问题描述】:
我使用 angular 的 cdkScrollable 在我的组件上实现了滚动事件。
我的代码如下所示
export class HomeComponent {
public hide = true;
constructor(public scrollDispatcher: ScrollDispatcher) {
this.scrollDispatcher.scrolled().subscribe((cdk: CdkScrollable) => {
offset = cdk.getElementRef().nativeElement.scrollTop || 0;
if (offset > 50) {
this.hide = false;
} else {
this.hide = true;
}
});
}
}
而我的home.component.html 有以下代码
<p>{{hide}}</p>
问题是 hide 的值即使滚动超过 64 也不会改变,但在 console.log 中它会改变。
我做错了什么?
【问题讨论】:
-
您找到解决方案了吗?我遇到了同样的问题,并且区域建议不起作用。
标签: angular angular6 angular-cdk