我正在使用DynamicComponentLoader
将组件动态加载到菜单栏中。
这是我的组件类的样子:
@Component({
selector: 'create-submenu-component',
templateUrl: 'common/create/create.component.html',
styleUrls: ['common/create/create.component.css'],
directives: [CreateAssetComponent]
})
export class CreateSubmenuComponent {
public model: Model;
constructor(private _modelService:ModelService, public http: Http) {
this.model = this._modelService.getModel();
}
}
动态组件创建方法:
constructor(public injector:Injector){}
loadCreateSubMenu(){
this.dcl.loadAsRoot(CreateSubmenuComponent, '#Create', this.injector);
}
当我尝试加载包含服务的组件时,我收到以下错误:
Cannot resolve all parameters for 'CreateSubmenuComponent'(undefined, Http). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'CreateSubmenuComponent' is decorated with Injectable.
正在注入的服务显示为未定义。子菜单不依赖服务的组件可以正常加载。如何将服务注入动态创建的组件?