Reputation: 1060
I am creating a directive in VSCode Editor which loads a html page on specifying a given path:
Below is the code for same:
@Directive({
selector: 'html-outlet'
})
export class HtmlOutlet {
@Input() html: string;
constructor(private vcRef: ViewContainerRef, private compiler: Compiler) {
}
ngOnChanges() {
const html = this.html;
if (!html) return;
@Component({
selector: 'dynamic-comp',
templateUrl: html
})
class DynamicHtmlComponent { };
@NgModule({
imports: [CommonModule],
declarations: [DynamicHtmlComponent]
})
class DynamicHtmlModule { }
this.compiler.compileModuleAndAllComponentsAsync(DynamicHtmlModule)
.then(factory => {
const compFactory = factory.componentFactories.find(x => x.componentType === DynamicHtmlComponent);
const cmpRef = this.vcRef.createComponent(compFactory, 0);
});}}
This code used to work perfectly fine untill i upgraded app to angular 6. I am getting below error now :
Runtime compiler is not loaded Error stack trace: Error: Runtime compiler is not loaded at Le (main.00612d315fe86075b5fb.js:1) at t.compileModuleAndAllComponentsAsync
Can i get some help in this
Upvotes: 2
Views: 1802
Reputation: 1920
If you are running the application in --prod mode it will default to AOT, which doesn't provide the compiler.
I don't think that the Angular team is encouraging the pattern of using the compiler at runtime at all.
Upvotes: 1