本文整理匯總了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);
});
}