ngx完美的滚动条更新功能未定义? [英] ngx perfect scrollbar update function undefined?

查看:61
本文介绍了ngx完美的滚动条更新功能未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

解决方案

通过使用 https修复了该问题://npm.taobao.org/package/perfect-scrollbar 我使用本机元素,然后使用更新进行了引用.像这样

 从'perfect-scrollbar'导入PerfectScrollbar;@ViewChild('perfectScroll')perfectScroll:ElementRef;ps;构造函数(私有psb:PerfectScrollService){}ngOnInit(){this.ps =新的PerfectScrollbar(this.pScroll.nativeElement,{wheelSpeed:2wheelPropagation:是的,minScrollbarLength:20});this.psb.setBar(this.ps);} 

在我的perfectScrollService中,我创建了一个实例,然后每次更改内容时都称为update

 从'@ angular/core'导入{可注入};@Injectable({providerIn:'root'})导出类PerfectScrollService {perfectScrollBar:任何;constructor(){}setBar(psb){this.perfectScrollBar = psb;}更新() {this.perfectScrollBar.update();}} 

然后像这样使用它

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

This is the first time i'm trying to use perfect scroll so i might have missed something, but looking at the documentation it shows some functions that can be accessed using the directiveRef as follows

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

following this i tried to use the update because i noticed the container wouldn't update with new items unless i resized the window so i checked the object only to find that the update function is undefined and missing from the directiveRef contrary to what is stated by the docs.

would really be thankful if anyone can shed light on this issue and point me in the right direction in case I missed anything along the way. Thank you

解决方案

fixed it by using https://npm.taobao.org/package/perfect-scrollbar I made a reference using Native element and then using update. like this

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);
}

in my perfectScrollService I made an instance then called update everytime the content was changed

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

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

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

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

}

and then used it like this

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

这篇关于ngx完美的滚动条更新功能未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆