2017-07-02 38 views
0

我有一个组件,它包含一个模态。从其他组件打开模态组件

<div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true"> 
    <div class="modal-dialog modal-lg"> 
     <div class="modal-content"> 
     <div class="modal-header"> 
      <h4 class="modal-title pull-left">Large modal</h4> 
      <button type="button" class="close pull-right" (click)="lgModal.hide()" aria-label="Close"> 
      <span aria-hidden="true">&times;</span> 
      </button> 
     </div> 
     <div class="modal-body"> 
      {{current}} 
     </div> 
     </div> 
    </div> 
    </div> 

我开模与@ViewChild('lgModal') modal;,并呼吁this.modal.show();

,但我想HTML代码中分离,所以是有可能从组件A调用组件B

+0

https://stackoverflow.com/questions/37888361/ng2-bootstrap-call-modal-defined-in-child-component-from-parent-compent – yurzui

+0

可能重复[ng2-bootstrap显示/隐藏模式作为子组件](https://stackoverflow.com/questions/42735858/ng2-bootstrap-show-hide-modal-as-child-component) – Aravind

回答

0

我会建议你创建一个对话框组件服务,你可以使用任何你。您只需将其作为服务注入并使用提供的方法填充对话框中的相关内容即可。

一个例子,刚发现一个Stackoverflow thread