2017-02-22 57 views
2

關閉模式我有一個自定義按鈕模型上點擊

<modal #modal> 
     <modal-header [show-close]="true"> 
      Header Text 
     </modal-header> 
     <modal-body> 
      Body Text 
     </modal-body> 
     <modal-footer> 
      <button type="button" class="btn btn-default" data-dismiss="modal" (click)="modal.dismiss()">Cancel</button> 
      <button type="button" class="btn btn-primary" (click)="SaveProject()">Ok</button> 
     </modal-footer> 
    </modal> 

在組件方面我有代碼SaveProject()

SaveProject() { 
//  Some Logic 

    } 

我想關閉模式的邏輯完成後, 。對於這一點,我在組件頁面

import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal'; 

實現了這個在出口類我有

modal: ModalComponent; 

而在我的單擊事件我有

SaveProject() { 
//  Some Logic 
this.modal.close(); 
    } 

但它不工作

回答

1

您需要使用ViewChild,如上所述。

@ViewChild('modal') 
modal: ModalComponent; 

然後你可以使用close甚至dismiss如果你想,這取決於你的使用情況:

SaveProject() { 
    this.modal.close(); 
    // this.modal.dismiss(); 
} 

更多信息here,摘錄從頁:

close(value?: any): Promise<any> 

關閉次數模態。關閉的原因被髮射。返回一個承諾,用於解決模態完全隱藏時傳遞的值。

dismiss(): Promise 

解除模態。 onDismiss的原因被髮射。返回一個承諾,可以在模態完全隱藏時解決。