我有一个角度子组件,其父组件是一个模态窗口(我正在使用ngx-smart-mod来实现模态(。当模态窗口关闭时,使用该方法:
this.ngxSmartModalService.getModal('ModalNameComponent').close();
事实上,模态并没有被破坏,而只是被隐藏起来。如何通知子组件模式已关闭。有人知道吗?提前谢谢你!
我在具有不同外部库的模态中执行此操作的方法是在父级绑定到的子级上放置一个事件发射器。(这是纯 Angular,与使用哪个外部库无关(。
export class ChildComponent {
@Output() close: EventEmitter<void> = new Event<Emitter>();
// method is called from the child - maybe from a button click in your html
onClose(): void {
this.close.emit();
}
}
父母:
<app-child-component *ngIf="showModal" (close)="showModal=false">
</app-child-component>