ngx完美的滚动条更新功能未定义?

时间:2019-03-19 05:50:56

标签: javascript angular typescript angular6 scrollbar

这是我第一次尝试使用完美滚动,因此我可能会错过一些东西,但是查看文档,它显示了一些可以使用伪指令访问的功能,如下所示

https://www.npmjs.com/package/ngx-perfect-scrollbar

enter image description here

在此之后,我尝试使用此更新,因为我注意到除非重新调整窗口大小,否则容器不会使用新项目进行更新,因此我检查对象仅是发现update函数未定义且缺少DirectiveRef与文档中的规定相反。

enter image description here

如果有人能阐明这个问题并为我指出正确的方向,以防万一我错过任何事情,我将非常感谢。谢谢

2 个答案:

答案 0 :(得分:1)

每个js库都遵循一个传统模式,所有核心功能都添加到了原型中,因此对对象原型的任何更改都将反映在所有对象实例中。

enter image description here

您会发现将方法添加到原型here

的更多优势

图片参考:https://hackernoon.com/understand-nodejs-javascript-object-inheritance-proto-prototype-class-9bd951700b29

答案 1 :(得分:0)

使用https://npm.taobao.org/package/perfect-scrollbar对其进行了修复 我使用Native元素然后使用update进行了引用。像这样

import PerfectScrollbar from 'perfect-scrollbar';

@ViewChild('perfectScroll') perfectScroll: ElementRef;
ps;

constructor(private psb: PerfectScrollService) {}

ngOnInit() {
    this.ps = new PerfectScrollbar(this.pScroll.nativeElement, {
      wheelSpeed: 2,
      wheelPropagation: true,
      minScrollbarLength: 20
    });
    this.psb.setBar(this.ps);
}

在我的perfectScrollService中,我创建了一个实例,然后在每次更改内容时都调用了更新

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class PerfectScrollService {
  perfectScrollBar: any;
  constructor() { }

  setBar(psb) {
    this.perfectScrollBar = psb;
  }

  update() {
    this.perfectScrollBar.update();
  }

}

然后像这样使用它

    let newData;
    this.data[i].subscribe(
      value => (newData = value.concat(response.data[0]))
    );
    this.data$[i].next(newData);
    this.psb.update();