我正在使用ngx-perfect-scrollbar
我的 Angular 5 项目。div
当路线改变时,我想滚动到顶部。
仪表板.html
<div class="main-panel" [perfectScrollbar] #perfectscroll>
<router-outlet></router-outlet>
</div>
仪表板.ts
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
})
export class DashboardComponent implements OnInit {
@ViewChild('perfectscroll') perfectscroll: PerfectScrollbarDirective;
ngOnInit() {
this.router.events.subscribe((evt) => {
if (!(evt instanceof NavigationEnd)) {
return;
}
this.perfectscroll.scrollToTop()
});
}
}
但我得到这个错误:
TypeError: _this.perfectscroll.scrollToTop 不是函数