我在我的组件中使用了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>
问题在于即使滚动超过 64,hide 的值也不会改变,但在 console.log 中它却改变了。
我做错了什么?