From 96e673fef9c38e5aa92a2608c2d29cb9c1bc37c8 Mon Sep 17 00:00:00 2001
From: thekiba
Date: Fri, 21 Dec 2018 17:06:47 +0300
Subject: [PATCH] Added forRoot static method for PerfectScrollbarModule
---
README.md | 9 +--------
example/src/app/app.module.ts | 11 ++---------
src/lib/perfect-scrollbar.module.ts | 14 +++++++++++++-
3 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
index a19ab5b..e65f285 100644
--- a/README.md
+++ b/README.md
@@ -50,7 +50,6 @@ Providing the global configuration is optional and when used you should only pro
```javascript
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';
-import { PERFECT_SCROLLBAR_CONFIG } from 'ngx-perfect-scrollbar';
import { PerfectScrollbarConfigInterface } from 'ngx-perfect-scrollbar';
const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
@@ -61,13 +60,7 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
...
imports: [
...
- PerfectScrollbarModule
- ],
- providers: [
- {
- provide: PERFECT_SCROLLBAR_CONFIG,
- useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG
- }
+ PerfectScrollbarModule.forRoot(DEFAULT_PERFECT_SCROLLBAR_CONFIG)
]
})
```
diff --git a/example/src/app/app.module.ts b/example/src/app/app.module.ts
index fa75d12..cf1572e 100644
--- a/example/src/app/app.module.ts
+++ b/example/src/app/app.module.ts
@@ -4,8 +4,7 @@ import { BrowserModule } from '@angular/platform-browser';
import { FlexLayoutModule } from '@angular/flex-layout';
-import { PerfectScrollbarModule, PerfectScrollbarConfigInterface,
- PERFECT_SCROLLBAR_CONFIG } from 'ngx-perfect-scrollbar';
+import { PerfectScrollbarModule, PerfectScrollbarConfigInterface } from 'ngx-perfect-scrollbar';
import { AppComponent } from './app.component';
@@ -23,15 +22,9 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
imports: [
BrowserModule,
FlexLayoutModule,
- PerfectScrollbarModule
+ PerfectScrollbarModule.forRoot(DEFAULT_PERFECT_SCROLLBAR_CONFIG)
],
exports: [
- ],
- providers: [
- {
- provide: PERFECT_SCROLLBAR_CONFIG,
- useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG
- }
]
})
export class AppModule {}
diff --git a/src/lib/perfect-scrollbar.module.ts b/src/lib/perfect-scrollbar.module.ts
index ceafac0..d6396e6 100644
--- a/src/lib/perfect-scrollbar.module.ts
+++ b/src/lib/perfect-scrollbar.module.ts
@@ -1,9 +1,10 @@
-import { NgModule } from '@angular/core';
+import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PerfectScrollbarComponent } from './perfect-scrollbar.component';
import { PerfectScrollbarDirective } from './perfect-scrollbar.directive';
+import { PerfectScrollbarConfigInterface, PERFECT_SCROLLBAR_CONFIG } from './perfect-scrollbar.interfaces'
@NgModule({
imports: [CommonModule],
@@ -11,4 +12,15 @@ import { PerfectScrollbarDirective } from './perfect-scrollbar.directive';
exports: [CommonModule, PerfectScrollbarComponent, PerfectScrollbarDirective]
})
export class PerfectScrollbarModule {
+ static forRoot(config?: PerfectScrollbarConfigInterface): ModuleWithProviders {
+ return {
+ ngModule: PerfectScrollbarModule,
+ providers: [
+ {
+ provide: PERFECT_SCROLLBAR_CONFIG,
+ useValue: config
+ }
+ ]
+ };
+ }
}