zefoy / ngx-perfect-scrollbar

Angular wrapper library for the Perfect Scrollbar
MIT License
522 stars 116 forks source link

Cannot read property 'classList' of null #226

Open arturikoX opened 5 years ago

arturikoX commented 5 years ago

Hi, My versions are: "@angular/core": "5.2.0", "ngx-perfect-scrollbar": "^5.3.5", "@swimlane/ngx-datatable": "11.3.2".

So, ngx-datatable does not supprt ngx-perfectscrollbar, so we have a regular scrollbar there. The problem is that when table is in loading new data mode, the focus goes to parent or something, And the body is scrolling.

I tried to listen to scrolling event :

        this.componentScroll.PS_SCROLL_DOWN.subscribe((e: MouseEvent) => {
            if (this.isTableLoading) { 
            this.componentScroll.autoPropagation = false;
            this.componentScroll.disabled = true;
            if (e.stopPropagation && e.preventDefault) {
                e.stopPropagation();
                e.preventDefault();
                e.returnValue = false;
            }
        }
        if (!this.isTableLoading && !this.isTableHasRowsBelow) {
            this.componentScroll.disabled = false;
            this.componentScroll.autoPropagation = true;
        }
        });

So when scrolling event occur, check if table is loading, if yes, disable the ngx-perfect-scrollbar, Otherwise enable it again, But, I get this error :

image

Any help? Thanks, Artur

sconix commented 5 years ago

When are you adding those events? If you are doing it in ngOnInit try to do it in ngAfterViewInit. That error sounds like you are causing some change detection before DOM is ready for the PS.

arturikoX commented 5 years ago

The events are inside a Directive, inside AfterViewInit, it looks like when i'm disabling, the scrollbar still adding class to an unknow element : image

sconix commented 5 years ago

If you can somehow reproduce that in Stackblitz then I could have a look if it can be prevented in this library. The real problem is in PS lib, but there might be a way to prevent it in this library. Sadly I do not have time at the moment to start trying this from scratch so would need easy reproduction code to test and quickly check if I can do something about this.