UNPKG

ngx-dynamic-compiler

Version:

168 lines (160 loc) 5.41 kB
import { CommonModule } from '@angular/common'; import { Injectable, NgModule, Component, ViewChild, ViewContainerRef, Compiler, Input, Output, EventEmitter, defineInjectable, COMPILER_OPTIONS, CompilerFactory } from '@angular/core'; import { JitCompilerFactory } from '@angular/platform-browser-dynamic'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NgxDynamicCompilerService { constructor() { } } NgxDynamicCompilerService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ NgxDynamicCompilerService.ctorParameters = () => []; /** @nocollapse */ NgxDynamicCompilerService.ngInjectableDef = defineInjectable({ factory: function NgxDynamicCompilerService_Factory() { return new NgxDynamicCompilerService(); }, token: NgxDynamicCompilerService, providedIn: "root" }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NgxDynamicCompilerComponent { /** * @param {?} compiler */ constructor(compiler) { this.compiler = compiler; this.Data = {}; this.Template = ''; this.Output = new EventEmitter(); this.html = ''; this.returnUrl = '/'; this.showFilter = true; } /** * @return {?} */ ngOnInit() { this.compileTemplate(this.Data); } /** * @return {?} */ ngOnChanges() { } /** * @param {?} data * @return {?} */ compileTemplate(data) { /** @type {?} */ let metaData = { // template:this.template, template: this.Template, selector: 'ptv-template' }; /** @type {?} */ let factory = this.createComponentFactorySync(this.compiler, metaData, null, data); if (this.componentRef) { this.componentRef.destroy(); this.componentRef = null; } this.componentRef = this.container.createComponent(factory); } /** * @param {?} compiler * @param {?} metadata * @param {?} componentClass * @param {?} data * @return {?} */ createComponentFactorySync(compiler, metadata, componentClass, data) { /** @type {?} */ const cmpClass = componentClass || class RuntimeComponent { constructor() { this.Data = data; } }; /** @type {?} */ const decoratedCmp = Component(metadata)(cmpClass); class RuntimeModule { } RuntimeModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule], declarations: [decoratedCmp] },] }, ]; /** @type {?} */ let module = compiler.compileModuleAndAllComponentsSync(RuntimeModule); console.log(JSON.stringify(module.componentFactories)); return module.componentFactories.find((/** * @param {?} el * @return {?} */ el => el.componentType == decoratedCmp)); } /** * @return {?} */ ngOnDestroy() { if (this.componentRef) { this.componentRef.destroy(); this.componentRef = null; } } } NgxDynamicCompilerComponent.decorators = [ { type: Component, args: [{ selector: 'ngx-dc', template: ` <div #container> </div> ` }] } ]; /** @nocollapse */ NgxDynamicCompilerComponent.ctorParameters = () => [ { type: Compiler } ]; NgxDynamicCompilerComponent.propDecorators = { container: [{ type: ViewChild, args: ['container', { read: ViewContainerRef },] }], Data: [{ type: Input }], Template: [{ type: Input }], Output: [{ type: Output }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} compilerFactory * @return {?} */ function createCompiler(compilerFactory) { return compilerFactory.createCompiler(); } const ɵ0 = {}; class NgxDCModule { } NgxDCModule.decorators = [ { type: NgModule, args: [{ declarations: [NgxDynamicCompilerComponent], imports: [], providers: [ { provide: COMPILER_OPTIONS, useValue: ɵ0, multi: true }, { provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS] }, { provide: Compiler, useFactory: createCompiler, deps: [CompilerFactory] } ], exports: [NgxDynamicCompilerComponent] },] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NgxDynamicCompilerService, NgxDynamicCompilerComponent, createCompiler, NgxDCModule }; //# sourceMappingURL=ngx-dynamic-compiler.js.map