以前我在Angular1中使用ng-include进行动态模板加载 .
现在我开始使用Angular2 . Angular2没有ng-include feauture .
通过这个stackoverflow链接,我得到了该功能的自定义指令的解决方案
Dynamic template in templatURL in angular2
从以上链接帖子的解决方案我面临几个问题
我使用的是Angular2.4.0版本
在上面的帖子中有plunker链接 . 如果你在那里观察到了弹药柱
import {
Component, Input, ViewContainerRef, OnInit, ComponentResolver, ViewChild
} from "@angular/core";
import {FORM_DIRECTIVES} from "@angular/common";
现在我无法从@ angular / core获取@ angular / common和ComponentResolver的FROM_DIRECTIVES . 因为ComponentResolver被ComponentFactoryResolver取代 .
即使我对上面的plunker链接进行更改我也会收到错误
caused by: No component factory found for MyNgIncludeContent. Did you add it to @NgModule.entryComponents
甚至我将entrycomponents添加到@NgModule装饰器 .
请帮我解决这个问题,或者提出任何更好的方法 .
你可以在https://plnkr.co/edit/XVLcMl?p=preview找到我的问题