- angular-compile.git
- src
- CompileHtmlService.ts
This file ( 920B ) exceeds the allowed full mode (48 kb) size.
The editor full hight is disabled, only scrolling is allowed..
If you wish to edit a file, it is recommended to use the scroll mode as some users do not like the full height
mode, although some users like it.
import {
Component,
Compiler, NgModule,
Injectable
} from '@angular/core';
import {CompileHtmlServiceOptions} from "../typings/CompileHtmlServiceOptions";
@Injectable()
export class CompileHtmlService {
constructor(private compiler: Compiler) {}
public compile(opts: CompileHtmlServiceOptions) {
@Component({
template: opts.template || ''
})
class TemplateComponent {
ref = opts.ref;
}
@NgModule({
imports: opts.imports,
declarations: [TemplateComponent]
})
class TemplateModule {}
const compiled = this.compiler.compileModuleAndAllComponentsSync(TemplateModule);
const factory = compiled.componentFactories.find((comp) =>
comp.componentType === TemplateComponent
);
opts.container.clear();
opts.container.createComponent(factory);
}
}