5

I have used the below code in order to load dynamically components in my app. As you may know, compileComponentAsync is deprecated in RC6. I want to find a similar solution. Maybe I should use compileModuleAsync. But I couldn't find something. Has anyone an idea?

this.compiler.compileComponentAsync(component)
    .then(factory => {
        const injector = ReflectiveInjector.fromResolvedProviders([], this.vcRef.parentInjector);
        this.vcRef.createComponent(factory, 0, injector, []);
...  ...
Steven Lignos
  • 217
  • 3
  • 10
  • 1
    See also http://stackoverflow.com/questions/38888008/how-can-i-use-create-dynamic-template-to-compile-component-with-angular2-rc5/38888009#38888009 – Günter Zöchbauer Sep 01 '16 at 19:48

1 Answers1

7

you may use compileModuleAndAllComponentsAsync it returns ModuleWithComponentFactories.

this.compiler.compileModuleAndAllComponentsAsync(module).then(_module => {
            _module.componentFactories => Gives factory for all the components which are exported from the module.
        });

Read more about it here

Hope this helps!!

Madhu Ranjan
  • 17,334
  • 7
  • 60
  • 69