Angular ng引导模式的ElementRef

Angular ng引导模式的ElementRef,angular,Angular,我想引用angular 2组件中ng引导模式中的html元素 实时视图 &时代; 接近 如何在angular 2组件中引用#liveViewCanvas?当通过@viewchild引用时,我得到“错误类型错误:无法读取未定义的属性'nativeElement'”,就像NgIf指令一样,您只能在DOM中使用引用。如果您想操作模板,只需使用模板和模态逻辑创建一个组件,然后启动它 export class NgbdModalComponent { constructor(private mo

我想引用angular 2组件中ng引导模式中的html元素


实时视图
&时代;
接近

如何在angular 2组件中引用
#liveViewCanvas
?当通过@viewchild

引用时,我得到“错误类型错误:无法读取未定义的属性'nativeElement'”,就像NgIf指令一样,您只能在DOM中使用引用。如果您想操作模板,只需使用模板和模态逻辑创建一个组件,然后启动它

export class NgbdModalComponent {
  constructor(private modalService: NgbModal) {}

  open() {
    const modalRef = this.modalService.open(NgbdModalContent);
    modalRef.componentInstance.name = 'World';
  }
}
也许是这样的

const modalRef = this.modalService.open(HoldingModalsProductCreateComponent,{backdrop: 'static'});
modalRef._windowCmptRef.hostView.rootNodes[0];

你查清楚了吗?我遇到了同样的问题我遇到了与OP相同的问题。我尝试了上面的方法,但是componentInstance是未定义的(尽管modalRef中有其他信息);我改为打开内容(我无法更改,所以这种方法对我不起作用)。
const modalRef = this.modalService.open(HoldingModalsProductCreateComponent,{backdrop: 'static'});
modalRef._windowCmptRef.hostView.rootNodes[0];