Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular ngx完美滚动条:如何引用typescript中的指令?_Angular_Scroll_Perfect Scrollbar - Fatal编程技术网

Angular ngx完美滚动条:如何引用typescript中的指令?

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

我在Angular 5项目中使用了
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;
}