简体   繁体   中英

Deprecated compiler module in Angular 13

with Angular 13 I'm seeing deprecations for the usual compiler tools to instantiate an NgModule and Here is my usual go-to code for loading a module

    container: ViewContainerRef
    const mod = this.compiler.compileModuleAndAllComponentsSync(TemplateModule);
    const factory = mod.componentFactories.find((comp) =>
        comp.componentType === TemplateComponent
    );
    const component = this.container.createComponent(factory);

Low-level service for running the angular compiler during runtime to create ComponentFactorys, which can later be used to create and render a Component instance.

Each @NgModule provides an own Compiler to its injector, that will use the directives/pipes of the ng module for compilation of components.

@publicApi

@deprecated Ivy JIT mode doesn't require accessing this symbol. See JIT API changes due to ViewEngine deprecation for additional context.

Looking V13 change for above update.

Without using the factory, you have to use ViewContainerRef.createComponent . refer to the below link https://stackoverflow.com/a/72174262/19077843

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM