gpt4 book ai didi

Angular 2 NgbModal NgbActiveModal 关闭事件模式

转载 作者:太空狗 更新时间:2023-10-29 17:12:08 25 4
gpt4 key购买 nike

我正在使用 Angular 2,我正在使用一个表单模式,我有两个组件,从一个组件我以这种方式打开表单模式:

import { Component, OnInit, Output} from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { MyFormComponent } from '......./....';


@Component({
moduleId: module.id,
selector: 'my-component',
templateUrl: 'my-component.html'
})
export class MyComponent implements OnInit {

private anyData: any;
private anyDataForm: any;


constructor(
private modalService: NgbModal
) { }

ngOnInit(): void {
}

open() {
const modalRef = this.modalService.open(MyFormComponent, { size: 'lg' });
modalRef.componentInstance.anyDataForm = this.anyData;
}

possibleOnCloseEvet() {
//Do some actions....
}

}

open() 方法从 my-component.html 上的按钮触发

在 Form 组件(模态组件)上,我用它来关闭实际模态(从它本身)

import { Component, OnInit, OnDestroy, Input } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

@Component({
moduleId: module.id,
selector: 'my-form-component',
templateUrl: 'my-form-component.html'
})
export class MyFormComponent implements OnInit, OnDestroy {

@Input() anyDataForm: any;

constructor(
public activeModal: NgbActiveModal
) {
}

ngOnInit(): void {
}

//Some form code...

OnSubmit() {
this.activeModal.close(); //It closes successfully
}

ngOnDestroy(): void {
}

}

我需要做的是在调用方组件上触发某种“关闭时”事件,以便仅在模式关闭时在调用方中执行某些操作。 (不能使用事件发射器)

组件打开器有什么方法可以知道模态何时关闭?我还没有找到任何明确的例子。

最佳答案

试试这个:

const modalRef = this.modalService.open(MyFormComponent, { size: 'lg' });
modalRef.componentInstance.anyDataForm = this.anyData;

modalRef.result.then((data) => {
// on close
}, (reason) => {
// on dismiss
});

关于Angular 2 NgbModal NgbActiveModal 关闭事件模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44580255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com