Angular 2 Dynamically Bootable Application Components

Is it possible to use dynamically bootable application components depending on whether the element exists.

I would like something like ...

export class AppModule { 

constructor() {

}   

ngDoBootstrap(appRef: ApplicationRef) {
    for(let component of components) {
       if(document.querySelector(component.selector)){
           appRef.bootstrap(component);
       }
    }
}

}
+4
source share
1 answer

No, you need to check yourself whether the item is available in the DOM, and then call platformBrowserDynamic().bootstrapModule(AppModule);or appRef.bootstrap(component);somehow miss it.

See also https://github.com/angular/angular/issues/11730#issuecomment-252677321

0
source

Source: https://habr.com/ru/post/1663632/