本文整理汇总了TypeScript中@angular/core.Compiler.compileModuleAndAllComponentsAsync方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Compiler.compileModuleAndAllComponentsAsync方法的具体用法?TypeScript Compiler.compileModuleAndAllComponentsAsync怎么用?TypeScript Compiler.compileModuleAndAllComponentsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/core.Compiler
的用法示例。
在下文中一共展示了Compiler.compileModuleAndAllComponentsAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
System.import('./dist/lazy.bundle.js').then((module: any) => {
this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule)
.then((compiled) => {
const factory = compiled.componentFactories[0];
this.container.createComponent(factory);
});
});
示例2: createComponentFactory
export function createComponentFactory(compiler: Compiler,
metadata: Component):
Promise<ComponentFactory<any>> {
const cmpClass = class DynamicComponent {};
const decoratedCmp = Component(metadata)(cmpClass);
@NgModule({
imports: [ CommonModule ],
declarations: [decoratedCmp],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ] })
class DynamicHtmlModule { }
return compiler.compileModuleAndAllComponentsAsync(DynamicHtmlModule)
.then((moduleWithComponentFactory: ModuleWithComponentFactories<any>) =>
{
return moduleWithComponentFactory.componentFactories.find
((x) => x.componentType === decoratedCmp);
});
}
示例3: createComponentFactory
/**
* Use the runtime compiler to create this Component Factory dynamically as well as a dynamic module
* to wrapp it
*
* This will create a dynamic module and a dynamic component by calling compiler.compileModuleAndAllComponentsAsync and passing in a NgModule
* that we create on the fly wrapping our newly created component
*
* @param {Object} decoratorData
* The medatata for this component we got from typedoc
*
* @param {Function} cb
* The callback to call when we create the component returning inside our component Factor
*
* With this Component Factory we can then inject it in the View by using ViewContainerRef and Injector
* See @dynamicOutlot.component.ts
*/
createComponentFactory(decoratorData: Object, cb: Function) {
// first get our metadata
let metadata = this.createMetadata(decoratorData);
let factory;
const cmpClass = class DynamicComponent { };
const decoratedCmp = Component(metadata)(cmpClass);
@NgModule({
imports: [BrowserModule],
declarations: [decoratedCmp]
})
class DynamicModule { }
this.compiler.compileModuleAndAllComponentsAsync(DynamicModule).then((moduleWithComponentFactory) => {
const compFactory = moduleWithComponentFactory.componentFactories
.find(x => x.componentType === decoratedCmp);
cb(compFactory);
});
}