2017-07-02 43 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