11import { CommonModule } from '@angular/common' ;
2- import { ModuleWithProviders , NgModule } from '@angular/core' ;
2+ import { ModuleWithProviders , NgModule , OpaqueToken } from '@angular/core' ;
33
44import { NotifierContainerComponent } from './components/notifier-container.component' ;
55import { NotifierNotificationComponent } from './components/notifier-notification.component' ;
@@ -8,6 +8,26 @@ import { NotifierAnimationService } from './services/notifier-animation.service'
88import { NotifierQueueService } from './services/notifier-queue.service' ;
99import { NotifierService } from './services/notifier.service' ;
1010
11+ // tslint:disable variable-name
12+ /**
13+ * Dependency Injection token for custom notifier options
14+ */
15+ export const CustomNotifierOptions : OpaqueToken = new OpaqueToken ( 'NotifierOptions' ) ;
16+ // tslint:enable variable-name
17+
18+ /**
19+ * Factory for creating a notifier configuration object
20+ *
21+ * Sidenote:
22+ * This functionality had to be extracted from the NotifierModule.forRoot function, described below. Otherwhise, the Angular AoT compiler
23+ * would throw errors. For further details, also see:
24+ * - Angular issue #11262 <https://github.com/angular/angular/issues/11262>
25+ * - Angular issue #10789 <https://github.com/angular/angular/issues/10789>
26+ */
27+ export function notifierConfigFactory ( options : NotifierOptions ) : NotifierConfig {
28+ return new NotifierConfig ( options ) ;
29+ }
30+
1131/**
1232 * Notifier module
1333 */
@@ -38,8 +58,15 @@ export class NotifierModule {
3858 ngModule : NotifierModule ,
3959 providers : [
4060 {
61+ provide : CustomNotifierOptions ,
62+ useValue : options
63+ } ,
64+ {
65+ deps : [
66+ CustomNotifierOptions
67+ ] ,
4168 provide : NotifierConfig ,
42- useValue : new NotifierConfig ( options )
69+ useFactory : notifierConfigFactory
4370 }
4471 ]
4572 } ;
0 commit comments