CodexBloom - Programming Q&A Platform

Angular 15 - How to Pass Data from Child to Parent Component Using EventEmitter in a Dynamic Form?

๐Ÿ‘€ Views: 1783 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-16
angular event-emitter parent-child-components TypeScript

I'm upgrading from an older version and I'm working on an Angular 15 application where I have a dynamic form with several child components, and I need to pass data back to the parent component whenever a value changes in one of the child components. I've implemented the EventEmitter to emit the value change from the child, but it's not reflecting in the parent. Hereโ€™s a simplified version of what Iโ€™ve done: In the child component, I have: ```typescript import { Component, EventEmitter, Output } from '@angular/core'; @Component({ selector: 'app-child', template: `<input (input)="onInputChange($event.target.value)" />` }) export class ChildComponent { @Output() valueChange = new EventEmitter<string>(); onInputChange(value: string) { this.valueChange.emit(value); } } ``` In the parent component, I am using the child component like this: ```html <app-child (valueChange)="onChildValueChange($event)"></app-child> <p>Value from child: {{ childValue }}</p> ``` And handling the emitted value in the parent component: ```typescript import { Component } from '@angular/core'; @Component({ selector: 'app-parent', template: `<app-child (valueChange)="onChildValueChange($event)"></app-child>` }) export class ParentComponent { childValue: string = ''; onChildValueChange(value: string) { this.childValue = value; } } ``` Despite this setup, the `childValue` in the parent component is not updating when I type in the input of the child component. I checked the console for errors but didnโ€™t find anything relevant. Iโ€™ve tried different binding strategies, but Iโ€™m still exploring. Is there something I might be missing? Any insights or alternative approaches would be appreciated! The stack includes Typescript and several other technologies. This is part of a larger web app I'm building. How would you solve this?