'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.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1