可以使用@ViewChild装饰器来获取对Angular模态框的引用,并在关闭时触发一个回调函数。
示例代码如下:
html文件:
ts文件:
import { Component, ViewChild } from '@angular/core'; import { ModalComponent } from 'app-modal';
@Component({ selector: 'my-component', templateUrl: './my.component.html', styleUrls: ['./my.component.scss'], }) export class MyComponent { @ViewChild('myModal', { static: false }) myModal: ModalComponent;
ngAfterViewInit() { this.myModal.onClose.subscribe(() => { this.doSomething(); }); }
doSomething() { // 这里执行需要执行的操作 } }
在示例代码中,@ViewChild装饰器用于获取对Angular模态框的引用。然后,我们在模态框关闭时触发了一个回调函数doSomething()。
在doSomething()函数中,您可以执行需要执行的操作,例如向服务器发送请求或更新应用程序状态。
请注意,这只是一种方法。您可以根据应用程序的需要使用其他技术来实现相同的操作。