Skip to content

Commit

Permalink
feat: allow registering dynamic components
Browse files Browse the repository at this point in the history
  • Loading branch information
Shlomi Assaf (shlassaf) committed Aug 23, 2016
1 parent 1c0de9d commit 250f234
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/components/angular2-modal/angular2-modal.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { ANALYZE_FOR_ENTRY_COMPONENTS, NgModule, ModuleWithProviders, Type } from '@angular/core';
import { EVENT_MANAGER_PLUGINS } from '@angular/platform-browser';

import { DOMOutsideEventPlugin, DOMOverlayRenderer } from './providers/index';
Expand Down Expand Up @@ -27,13 +27,35 @@ import { Overlay, ModalOverlay, OverlayDialogBoundary, OverlayTarget } from './o
]
})
export class ModalModule {
static forRoot(): ModuleWithProviders {
/**
* Returns a ModalModule pre-loaded with a list of dynamically inserted components.
* Since dynamic components are not analysed by the angular compiler they must register manually
* using entryComponents, this is an easy way to do it.
* @param entryComponents A list of dynamically inserted components (dialog's).
* @returns {{ngModule: ModalModule, providers: {provide: OpaqueToken, useValue: Array<Type|any[]>, multi: boolean}[]}}
*/
static withComponents(entryComponents: Array<Type | any[]>): ModuleWithProviders {
return {
ngModule: ModalModule,
providers : [
{ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: entryComponents, multi: true }
]
}
}

/**
* Returns a NgModule for use in the root Module.
* @param entryComponents A list of dynamically inserted components (dialog's).
* @returns ModuleWithProviders
*/
static forRoot(entryComponents?: Array<Type | any[]>): ModuleWithProviders {
return {
ngModule: ModalModule,
providers: [
Overlay,
{ provide: OverlayRenderer, useClass: DOMOverlayRenderer },
{ provide: EVENT_MANAGER_PLUGINS, useClass: DOMOutsideEventPlugin, multi: true },
{ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: entryComponents || [], multi: true }
]
};
}
Expand Down

0 comments on commit 250f234

Please sign in to comment.