0

I am trying to dynamically load template url dyanmically in angular AOT

https://angular.io/docs/ts/latest/cookbook/dynamic-component-loader.html

Used code but not working

 ngAfterViewInit(): void {
    const moduleName = this._module.instance.constructor.name;
    const tmpCmp = Component({
      moduleId: moduleName,
      templateUrl: '/assets/templates/faqs/faqs.' + environment.vendor_prefix + '.component.html'
    })(class {});
    const tmpModule = NgModule({ declarations: [tmpCmp] })(class {});
    this._compiler.compileModuleAndAllComponentsAsync(tmpModule).then(factories => {
      const factory = factories.componentFactories[0];
      const cmpRef = factory.create(this._injector, [], null, this._module);
      cmpRef.instance.name = 'dynamic';
      this.vc.insert(cmpRef.hostView);
    });
  }

I am getting an error message as Runtime compiler is not loaded. I also checked this one too but no way to load template Url dynamically.

https://stackblitz.com/edit/angular-aot-dynamic-compile-module-wtnhzx?file=app%2Flazy.module.ts

Aman Jain
  • 384
  • 1
  • 3
  • 15

0 Answers0