单击关闭模式

时间:2017-02-22 08:28:56

标签: angular

我有一个带有自定义按钮的模型

 <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 个答案:

答案 0 :(得分:1)

您需要使用提及的ViewChild

@ViewChild('modal')
modal: ModalComponent;

如果您愿意,可以使用close甚至dismiss,具体取决于您的使用情况:

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

更多信息here,摘自页面:

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

关闭模态。导致onClose被发出。返回一个promise,它解析在完全隐藏模态时传递给close的值。

dismiss(): Promise
     

驳回模态。导致发出onDismiss。返回在完全隐藏模态时解析的promise。

相关问题