DynamicComponentLoader 主要的能力就是动态加载组件:
文档给出了3个用法
- 1
 
constructor(dcl: DynamicComponentLoader, injector: Injector) {  | 
loadAsRoot - (子组件名字,用于定位插入的节点位置,injector)
效果是 子组件的Template 插入到了父组件中 id=”child “ 标签里面
<child id="child">a</child>  | 
- 2
 
constructor(dcl: DynamicComponentLoader, elementRef: ElementRef) {  | 
loadIntoLocation (子组件,elementRef, 锚点名字 )
 效果是 找到父组件里的锚点位置标签
 把 子组件 标签插入 锚点标签下面(不是里面)
<child></child>  | 
3
loadNextToLocation(子组件 ,子组件,elementRef )
直接发子组件插入到父组件下面 (不是里面)
<parent-component>Parent (<child id="child"></child>)(<child></child>)</parent-component>
<child-component><div>good</div></child-component>
延伸下:
@Injectable()  | 
 这里有几种View,AppViewManager 是用来操作view
 View container 可以包含两种view
- hostViewRef —
 - Embedded Views — TemplateRef_ 请查看*ngIf 源码解读
 
loadAsRoot(type: Type, overrideSelector: string, injector: Injector, onDispose?: () => void,  | 
return this._compiler.compileInHost(type).then(hostProtoViewRef => {  | 
https://github.com/dreambo8563/node_angular2/blob/ng-pages/app/components/CompLoaderSample.ts