import { Component } from '@angular/core'; import { CmModalService } from '../../../../../../components/cosmos.module'; @Component({ selector: 'cm-modal-doc-3', templateUrl: './modal-doc-3.component.html', }) export class ModalDoc3Component { currentModal: any; isConfirmLoading = false; constructor(private modalService: CmModalService) { } showModal() { const modal = this.modalService.open({ title: '对话框标题', content: '纯文本内容,点确认 1 秒后关闭', closable: false, showConfirmLoading: true, onOk() { return new Promise((resolve) => { setTimeout(resolve, 1000); }); }, onCancel() { } }); } showModalForTemplate(titleTpl: any, contentTpl: any, footerTpl: any) { this.currentModal = this.modalService.open({ title: titleTpl, content: contentTpl, footer: footerTpl, maskClosable: false, onOk() { console.log('Click ok'); } }); } handleOk(e: any) { this.isConfirmLoading = true; setTimeout(() => { /* destroy方法可以传入onOk或者onCancel。默认是onCancel */ this.currentModal.destroy('onOk'); this.isConfirmLoading = false; this.currentModal = null; }, 1000); } }