Skip to content

Commit

Permalink
fix(aot): Fixed error occuring when using NotifierModule.forRoot with
Browse files Browse the repository at this point in the history
AoT

- Extracted NotifierConfig provider into a factory
- Added a new DI Token for custom options

Closes #5
  • Loading branch information
dominique-mueller committed Feb 5, 2017
1 parent 53091cf commit a501f40
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/notifier.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { ModuleWithProviders, NgModule, OpaqueToken } from '@angular/core';

import { NotifierContainerComponent } from './components/notifier-container.component';
import { NotifierNotificationComponent } from './components/notifier-notification.component';
Expand All @@ -8,6 +8,26 @@ import { NotifierAnimationService } from './services/notifier-animation.service'
import { NotifierQueueService } from './services/notifier-queue.service';
import { NotifierService } from './services/notifier.service';

// tslint:disable variable-name
/**
* Dependency Injection token for custom notifier options
*/
export const CustomNotifierOptions: OpaqueToken = new OpaqueToken( 'NotifierOptions' );
// tslint:enable variable-name

/**
* Factory for creating a notifier configuration object
*
* Sidenote:
* This functionality had to be extracted from the NotifierModule.forRoot function, described below. Otherwhise, the Angular AoT compiler
* would throw errors. For further details, also see:
* - Angular issue #11262 <https://github.com/angular/angular/issues/11262>
* - Angular issue #10789 <https://github.com/angular/angular/issues/10789>
*/
export function notifierConfigFactory( options: NotifierOptions ): NotifierConfig {
return new NotifierConfig( options );
}

/**
* Notifier module
*/
Expand Down Expand Up @@ -38,8 +58,15 @@ export class NotifierModule {
ngModule: NotifierModule,
providers: [
{
provide: CustomNotifierOptions,
useValue: options
},
{
deps: [
CustomNotifierOptions
],
provide: NotifierConfig,
useValue: new NotifierConfig( options )
useFactory: notifierConfigFactory
}
]
};
Expand Down

0 comments on commit a501f40

Please sign in to comment.