Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bisubus/fbef01fdb3b14e7349aead9b00701260 to your computer and use it in GitHub Desktop.

Select an option

Save bisubus/fbef01fdb3b14e7349aead9b00701260 to your computer and use it in GitHub Desktop.

Revisions

  1. bisubus revised this gist Feb 17, 2018. 1 changed file with 14 additions and 10 deletions.
    24 changes: 14 additions & 10 deletions AppModule.ts
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    import { Inject, ApplicationRef } from '@angular/core';

    import { Inject, Type, ApplicationRef, ComponentFactoryResolver } from '@angular/core';
    import { DOCUMENT } from '@angular/common';

    @NgModule({
    @@ -7,17 +8,20 @@ import { DOCUMENT } from '@angular/common';
    entryComponents: [App, Bpp]
    })
    export class AppModule {
    constructor(@Inject(DOCUMENT) private _document: any) {}
    static bootstrapComponents: Type[] = [App, Bpp];

    constructor(
    @Inject(DOCUMENT) private _document: any,
    private _componentFactoryResolver: ComponentFactoryResolver
    ) {}

    ngDoBootstrap(applicationRef: ApplicationRef) {
    const document = this._document;

    if (document.querySelector('app')) {
    applicationRef.bootstrap(App);
    }

    if (document.querySelector('bpp')) {
    applicationRef.bootstrap(Bpp);
    for (const component of AppModule.bootstrapComponents) {
    const { selector } = this._componentFactoryResolver.resolveComponentFactory(component);

    if (this._document.querySelector(selector)) {
    applicationRef.bootstrap(component);
    }
    }
    }
    }
  2. bisubus created this gist Feb 16, 2018.
    1 change: 1 addition & 0 deletions Angular multiple optional bootstrap (entry) components
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    23 changes: 23 additions & 0 deletions AppModule.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    import { Inject, ApplicationRef } from '@angular/core';
    import { DOCUMENT } from '@angular/common';

    @NgModule({
    imports: [BrowserModule],
    declarations: [App, Bpp],
    entryComponents: [App, Bpp]
    })
    export class AppModule {
    constructor(@Inject(DOCUMENT) private _document: any) {}

    ngDoBootstrap(applicationRef: ApplicationRef) {
    const document = this._document;

    if (document.querySelector('app')) {
    applicationRef.bootstrap(App);
    }

    if (document.querySelector('bpp')) {
    applicationRef.bootstrap(Bpp);
    }
    }
    }