1 import {Directive, Input, ElementRef} from '@angular/core';
2 import * as PerfectScrollbar from 'perfect-scrollbar';
4 interface IPerfectScrollbarOptions {
6 wheelPropagation?: boolean;
7 minScrollbarLength?: number;
8 useBothWheelAxes?: boolean;
10 suppressScrollX?: boolean;
11 suppressScrollY?: boolean;
12 scrollXMarginOffset?: number;
13 scrollYMarginOffset?: number;
14 includePadding?: boolean;
18 selector: '[perfectScrollbar]'
20 export class PerfectScrollbarDirective {
21 @Input() public perfectScrollbarOptions: IPerfectScrollbarOptions;
23 private psOptions: IPerfectScrollbarOptions;
24 private updatingPS: boolean;
26 constructor(public elemRef:ElementRef) {
27 console.log('PSbar: Constructor');
28 this.psOptions = Object.assign({}, this.perfectScrollbarOptions);
29 this.updatingPS = false;
33 console.log('PSbar: Initializing');
34 PerfectScrollbar.initialize(this.elemRef.nativeElement, this.psOptions);
37 public ngAfterContentChecked() {
38 // update perfect-scrollbar after content is checked (updated) - bounced
39 if (!this.updatingPS) {
40 this.updatingPS = true;
42 this.updatingPS = false;
43 PerfectScrollbar.update(this.elemRef.nativeElement);
48 public ngOnDestroy() {
49 PerfectScrollbar.destroy(this.elemRef.nativeElement);