我正在尝试构建自己的Modal组件,我可以在整个Angular2应用程序中重用它.我正在考虑不同的方法,我想知道是否有可能创建@Component它也作为@Injectable?我正在考虑这个,因为我想为Modal构建一个模板,并将其保存在一个地方.
谢谢
我有注射ElementRef到我的问题Injectable.这是我的代码:
import {Injectable, DynamicComponentLoader, ElementRef, Inject} from "angular2/core";
import {Modal} from './Modal';
@Injectable()
export class ModalService{
constructor(public _dcl:DynamicComponentLoader, public _el:ElementRef){
}
createModal(parent){
this._dcl.loadIntoLocation(Modal,this._el, 'modal')
}
}
Run Code Online (Sandbox Code Playgroud)
我的Modal:
从"angular2/core"导入{Component};
@Component({
selector: 'modal',
templateUrl: 'app/common/modal/Modal.html'
})
export class Modal{
constructor(){
}
}
Run Code Online (Sandbox Code Playgroud)
这让我产生以下错误:
没有ElementRef的提供者!(HomeComponent - > ModalService - > ElementRef)
为什么?