angularcomponentsangular-dynamic-componentsangular13

how to fetch data from dynamically rendered component in angular


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


Solution

  • 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