Issue with data communication between a modal child component and a parent component using...

Discussão em 'Angular' iniciado por Hardy Rakoto, Março 26, 2025.

  1. Hardy Rakoto

    Hardy Rakoto Guest

    I'm having trouble managing data communication between a parent component and a modal child component in an Angular application. The parent component opens a modal (child component), and after an event (such as scanning a barcode), I need to send the data (the barcode) back to the parent component. I'm using an EventEmitter to emit this data from the child component to the parent.

    However, when I try to emit the data, the parent doesn't receive the expected data. Instead, I get undefined.

    The parent component calls this.dialogService.showModal() to display the modal. The child modal component processes the barcode scan and emits the data using EventEmitter. The parent component listens for this emitted event, but the result is always undefined. function on parent component:

    public async startScan(): Promise<void> {
    const modal = await this.dialogService.showModal({
    component: ScannerComponent,
    cssClass: 'barcode-scanning-modal',
    showBackdrop: false,
    componentProps: {
    pushData: new EventEmitter<Barcode>()
    },
    });
    }



    child component:

    pushData = output<Barcode>();
    private processDetectedBarcode(barcode: Barcode): void {
    this.playBeepSound();
    this.pushData.emit(barcode);
    }

    Continue reading...

Compartilhe esta Página