Equivalent to legacy compileComponentAsync for loading dynamic components

I used the code below to load dynamically components in my application. As you know, compileComponentAsync is deprecated in RC6. I want to find a similar solution. Maybe I should use compileModuleAsync. But I could not find anything. Does anyone have an idea?

this.compiler.compileComponentAsync(component)
    .then(factory => {
        const injector = ReflectiveInjector.fromResolvedProviders([], this.vcRef.parentInjector);
        this.vcRef.createComponent(factory, 0, injector, []);
...  ...
+4
source share
1 answer

you can 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!

+6
source

Source: https://habr.com/ru/post/1653364/


All Articles