0

I want to pass a modal event from the child component to the modal's parent component, but i got an error " modalRf.componentInstance.confirmationEvent is not a function"

child Component: 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();
}

Parent Component

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();
           }
       }
   );
}
Fábio Nascimento
  • 2,644
  • 1
  • 21
  • 27

1 Answers1

0

Despite the fact it is better to add the confirmationEventin the selector (see this answer), I think you can simply fix your code by removing the parenthesis after modalRf.componentInstance.confirmationEvent

modalRf.componentInstance.confirmationEvent.subscribe(
   res => {
       if (res && res !== '' && res !== undefined) {
           this.afterConfirmChangementActivite();
       }
   }
);
C.Champagne
  • 5,381
  • 2
  • 23
  • 35