1

I have rendered some child components (which has some forms and field) in a parent component, now I am unable to fetch data from those child component's form's fields

4
  • Checkout the ControlValueAccessor interface if your child components are part of a form. Also when asking questions provide code of what you have tried thus far, else people will not be able to realy help you. Commented Jan 26, 2022 at 7:28
  • well I haven't done anything as I can't figure it out how can I do it Commented Jan 26, 2022 at 7:51
  • Since you don't seem to be passing down any data to your child component, you could use EventEmitters to receive data in the parent component, see angular.io/api/core/EventEmitter Commented Jan 26, 2022 at 8:18
  • there are multiple components (One component that is rendered multiple time on same screen )that are rendered and I will be fetching data from them all. Commented Jan 26, 2022 at 8:57

1 Answer 1

1

There are many ways to share data between components. One which could be via @Input / @Output. Some examples:

https://stackblitz.com/edit/sharing-data-between-angular-components-parent-to-1paiap?file=src%2Fapp%2Fparent%2Fparent.component.html

https://stackblitz.com/edit/angular-component-sharing-data-child-to-parent-rpgvld?file=src%2Fapp%2Fparent.ts

Or perhaps more suitable for your case could also be via service.

https://stackblitz.com/edit/stackblitz-angular-parent-and-children-communicat-fkrzvc?file=src%2Fapp%2Fmission.service.ts

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.