Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

Compiler

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.

See more...

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

      
      class Compiler {
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T>
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>>
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T>
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>): Promise<ModuleWithComponentFactories<T>>
clearCache(): void
clearCacheFor(type: Type<any>)
getModuleId(moduleType: Type<any>): string | undefined }

Provided in

  • 'root'

Description

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

Methods

Compiles the given NgModule and all of its components. All templates of the components have to be inlined.

      
      compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T>
    
Parameters
moduleType Type<T>
Returns

NgModuleFactory<T>

Compiles the given NgModule and all of its components

      
      compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>>
    
Parameters
moduleType Type<T>
Returns

Promise<NgModuleFactory<T>>

Same as compileModuleSync but also creates ComponentFactories for all components.

      
      compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T>
    
Parameters
moduleType Type<T>
Returns

ModuleWithComponentFactories<T>

Same as compileModuleAsync but also creates ComponentFactories for all components.

      
      compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>): Promise<ModuleWithComponentFactories<T>>
    
Parameters
moduleType Type<T>
Returns

Promise<ModuleWithComponentFactories<T>>

Clears all caches.

      
      clearCache(): void
    
Parameters

There are no parameters.

Returns

void

Clears the cache for the given component/ngModule.

      
      clearCacheFor(type: Type<any>)
    
Parameters
type Type<any>

Returns the id for a given NgModule, if one is defined and known to the compiler.

      
      getModuleId(moduleType: Type<any>): string | undefined
    
Parameters
moduleType Type<any>
Returns

string | undefined