2016-09-19 91 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 
      });