Abh*_*har 4 function call bootstrap-modal angular
我正在尝试在单击angular2using中使用的模态的背景(阴影部分)时调用一个函数(假设为“randomFunction”)NgbModal。
这是companyNumberComponent.html:  
<company-numbers-list (companyNumberModal)="modalService.open(companyNumberModal);"></company-numbers-list>
<template ngbModalContainer #companyNumberModal let-c="close" let-d="dismiss" id="companyNumberModal">
    <div class="modal-body">
        <company-number-modal></company-number-modal>
    </div>
    <div class="modal-footer text-center">
        <mi-button [type]="'info'" id="number_flow_close" [raised]="true" aria-label="close" (click)="c('Close click');
        ">Close</mi-button>
    </div>
这是companyNumberComponent.ts文件:  
@Component
 .....
 export class companyNumberComponent(){
     constructor(private modalService: NgbModal){}
     public randomFunction(){
         console.log("hi");
     }
 }
有人可以建议我如何进行此操作或如何在模态randomFunction()的dismiss()或close()函数中调用它。
似乎他们在文档中有你要找的东西,即ModalDismissReasons:
import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap';
open(content) {
  this.modalService.open(content).result.then((result) => {}, (reason) => {
    if (reason === ModalDismissReasons.ESC || // if you want to check ESC as well
        reason === ModalDismissReasons.BACKDROP_CLICK) {
        this.randomFunction();
      }
  });
}
此处似乎根本不包含关闭单击,因此您可以调用randomFunctiontemplate_ 中的单击事件
(click)="c('Close click'); randomFunction()"
或者您可以在组件中执行此操作,但在第一个回调中,如果单击关闭按钮,它似乎会向您抛出字符串'Close click'(或您在模板中定义的任何内容)。所以然后修改open如下:
open(content) {
  this.modalService.open(content).result.then((result) => {
    if(result === 'Close click') {
      this.randomFunction()
    }
  }, (reason) => {
      if (reason === ModalDismissReasons.ESC || 
          reason === ModalDismissReasons.BACKDROP_CLICK) {
          this.randomFunction();
      }
  });
}
| 归档时间: | 
 | 
| 查看次数: | 3431 次 | 
| 最近记录: |