我想将模态事件从子组件传递到模态的父组件,但出现错误“ modalRf.componentInstance.confirmationEvent不是函数”
子组件:ModalTestComponent.ts
@Input() idModal: string;
@Input() titre: string;
@Input() message: string;
@Output() confirmationEvent = new EventEmitter<any>();
constructor(public activeModal: NgbActiveModal) {
}
public confirmer() {
this.confirmationEvent.emit();
}
父组件
openActiviteModal() {
const modalRf = this.modalService.open(ModalTestComponent, 'TestModalId');
modalRf.componentInstance.titre = 'HELLO WORLD';
modalRf.componentInstance.message = 'THANKS';
modalRf.componentInstance.confirmationEvent().subscribe(
res => {
if (res && res !== '' && res !== undefined) {
this.afterConfirmChangementActivite();
}
}
);
}
答案 0 :(得分:0)
尽管最好在选择器中添加confirmationEvent
(请参阅this answer),但我认为您可以通过在modalRf.componentInstance.confirmationEvent
之后删除括号来简单地修复代码
modalRf.componentInstance.confirmationEvent.subscribe(
res => {
if (res && res !== '' && res !== undefined) {
this.afterConfirmChangementActivite();
}
}
);