I have an issue with injecting ElementRef
to my Injectable
. Here is my code:
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')
}
}
My Modal
:
import {Component} from "angular2/core";
@Component({
selector: 'modal',
templateUrl: 'app/common/modal/Modal.html'
})
export class Modal{
constructor(){
}
}
This yields me to the following error:
No provider for ElementRef! (HomeComponent -> ModalService -> ElementRef)
Why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…