1
1
import { CommonModule } from '@angular/common' ;
2
- import { ModuleWithProviders , NgModule } from '@angular/core' ;
2
+ import { ModuleWithProviders , NgModule , OpaqueToken } from '@angular/core' ;
3
3
4
4
import { NotifierContainerComponent } from './components/notifier-container.component' ;
5
5
import { NotifierNotificationComponent } from './components/notifier-notification.component' ;
@@ -8,6 +8,26 @@ import { NotifierAnimationService } from './services/notifier-animation.service'
8
8
import { NotifierQueueService } from './services/notifier-queue.service' ;
9
9
import { NotifierService } from './services/notifier.service' ;
10
10
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
+
11
31
/**
12
32
* Notifier module
13
33
*/
@@ -38,8 +58,15 @@ export class NotifierModule {
38
58
ngModule : NotifierModule ,
39
59
providers : [
40
60
{
61
+ provide : CustomNotifierOptions ,
62
+ useValue : options
63
+ } ,
64
+ {
65
+ deps : [
66
+ CustomNotifierOptions
67
+ ] ,
41
68
provide : NotifierConfig ,
42
- useValue : new NotifierConfig ( options )
69
+ useFactory : notifierConfigFactory
43
70
}
44
71
]
45
72
} ;
0 commit comments