【问题标题】:Dynamic component loading in RC5+ using string name parameters使用字符串名称参数在 RC5+ 中加载动态组件
【发布时间】:2016-09-19 11:26:32
【问题描述】:

在 RC5 之前,我正在动态加载组件,如下所示:

System.import('path/to/MyComponent')
            .then(fileContents => fileContents['MyComponent'])
            .then(component => {
                this.dynamicComponentLoader.loadNextToLocation(component, ..)
                    .then(() => {
                       ...
                    });
            });

从 RC5 开始,这不起作用,因为 DynamicComponentLoader 已被弃用。问题是它的前身ComponentFactoryResolver 将类型作为参数。我需要一种使用字符串名称加载组件的方法。我该怎么做?

【问题讨论】:

    标签: angular dynamic-loading


    【解决方案1】:

    设法这样做:

    System.import('path/to/MyComponent')
                .then(fileContents => fileContents['MyComponent'])
                .then(component => {
                    let factory = this.componentFactoryResolver.resolveComponentFactory(component);
                    this.container.createComponent(factory); //container: ViewContainerRef
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 2016-12-21
      • 2022-11-18
      • 2018-01-15
      • 1970-01-01
      相关资源
      最近更新 更多