相当于已弃用的compileComponentAsync,用于动态加载组件



我已经使用了下面的代码,以便在我的应用程序中动态加载组件。如你所知,compileComponentAsync在RC6中已被弃用。我想找到一个相似的解。也许我应该使用compileModuleAsync。但是我找不到东西。有人知道吗?

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

您可以使用compileModuleAndAllComponentsAsync,它返回ModuleWithComponentFactories

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

点击这里阅读更多信息

希望这有帮助!!

最新更新