2016-09-19 93 views
0

RC5之前,我加载组件动态是这样的:动态组件加载参数

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

由于RC5因为DynamicComponentLoader已被弃用,这并不工作。问题是它的前身ComponentFactoryResolver需要一个类型作为参数。我需要一种使用字符串名称加载组件的方法。我怎样才能做到这一点?

回答

0

设法做到这一点是这样的:

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