Compiler
本底层服务用于供 Angular 编译器在运行期间创建 ComponentFactory
,该工厂以后可用于创建和渲染组件实例。
Low-level service for running the angular compiler during runtime to create ComponentFactory
s, which can later be used to create and render a Component instance.
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
}
说明
每个 @NgModule
为其注入器提供一个自己的编译器,它将使用此 NgModule 的指令/管道来编译组件。
Each @NgModule
provides an own Compiler
to its injector, that will use the directives/pipes of the ng module for compilation of components.
属性
属性 | 说明 |
---|---|
compileModuleSync: <T>(moduleType: Type<T>) => NgModuleFactory<T> | 编译给定的 NgModule 及其所有组件。必须内联 Compiles the given NgModule and all of its components. All templates of the components listed in |
compileModuleAsync: <T>(moduleType: Type<T>) => Promise<NgModuleFactory<T>> | 编译给定的 NgModule 及其所有组件 Compiles the given NgModule and all of its components |
compileModuleAndAllComponentsSync: <T>(moduleType: Type<T>) => ModuleWithComponentFactories<T> | 与 compileModuleSync 相同,但还会为所有组件创建 ComponentFactory。 Same as compileModuleSync but also creates ComponentFactories for all components. |
compileModuleAndAllComponentsAsync: <T>(moduleType: Type<T>) => Promise<ModuleWithComponentFactories<T>> | 与 compileModuleAsync 相同,但还会为所有组件创建 ComponentFactory。 Same as compileModuleAsync but also creates ComponentFactories for all components. |
方法
清除所有缓存。 Clears all caches. |
参数没有参数。 返回值
|
清除给定组件/ngModule 的缓存。 Clears the cache for the given component/ngModule. |
返回给定 NgModule 的 ID(如果已定义且对编译器已知)。 Returns the id for a given NgModule, if one is defined and known to the compiler. |