Simplebar: SimpleBar freezes in Angular 4

Created on 26 Feb 2018  路  2Comments  路  Source: Grsmto/simplebar

I'm importing SimpleBar through modules as follows:

import * as SimpleBar from 'simplebar';

If I try to initialize it programatically the application freezes:

this.myScroll = new SimpleBar(document.getElementById('pageScroll'));

Is there a way to retrieve simplebar after it has been initialized like this?

<div id="pageScroll" data-simplebar></div>

Most helpful comment

In your component's ngAfterViewInit, do the following,

//ngZone is the injected NGZone service
this.ngZone.runOutsideAngular(() => {
    setTimeout(() => {
            //this.simpleBar is the ElementRef of simplebar element retrived via @ViewChild
            const scrollBar = new SimpleBar(this.simpleBar.nativeElement);
            //assuming you want to add a listener
            scrollBar.getScrollElement().addEventListener('scroll', (event) => {
                   //do your thing
            });
     });
});

All 2 comments

In your component's ngAfterViewInit, do the following,

//ngZone is the injected NGZone service
this.ngZone.runOutsideAngular(() => {
    setTimeout(() => {
            //this.simpleBar is the ElementRef of simplebar element retrived via @ViewChild
            const scrollBar = new SimpleBar(this.simpleBar.nativeElement);
            //assuming you want to add a listener
            scrollBar.getScrollElement().addEventListener('scroll', (event) => {
                   //do your thing
            });
     });
});

This worked thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TheeOhioState picture TheeOhioState  路  6Comments

andrey-evstigneev picture andrey-evstigneev  路  3Comments

RennerBink picture RennerBink  路  3Comments

barnu5 picture barnu5  路  5Comments

dyegonery picture dyegonery  路  5Comments