Angular ngx完美滚动条:如何引用typescript中的指令?
我在Angular 5项目中使用了Angular ngx完美滚动条:如何引用typescript中的指令?,angular,scroll,perfect-scrollbar,Angular,Scroll,Perfect Scrollbar,我在Angular 5项目中使用了ngx perfect scrollbar。当路线改变时,我想将div滚动到顶部 dashboard.html <div class="main-panel" [perfectScrollbar] #perfectscroll> <router-outlet></router-outlet> </div> 但我得到了这个错误: TypeError:_this.perfectscroll.scrollToT
ngx perfect scrollbar
。当路线改变时,我想将div
滚动到顶部
dashboard.html
<div class="main-panel" [perfectScrollbar] #perfectscroll>
<router-outlet></router-outlet>
</div>
但我得到了这个错误:
TypeError:_this.perfectscroll.scrollToTop不是一个函数
只要用这个:
@ViewChild(PerfectScrollbarDirective)perfectscroll:PerfectScrollbarDirective
您将有一个实例,然后可以调用scrollToTop()之类的函数。看看我的工作示例 在模板中:
<div class="perfectScroll" [perfectScrollbar] #psLeft="ngxPerfectScrollbar">...</div>
...
<div class="perfectScroll" [perfectScrollbar] #psRight="ngxPerfectScrollbar">...</div>
所有这些解决方案对我都不起作用。我已经把它修好了
scrollUp(): void {
const container = document.querySelector('.main-panel');
container.scrollTop = 0;
}
但是如果页面上有多个滚动条呢?这个问题解决了吗?请张贴或接受解决方案。
@ViewChild('psLeft') psLeft: PerfectScrollbarDirective;
@ViewChild('psRight') psRight: PerfectScrollbarDirective;
...
if (this.psRight) {
this.psRight.scrollToTop();
}
scrollUp(): void {
const container = document.querySelector('.main-panel');
container.scrollTop = 0;
}