Encountering an issue while attempting to display a child component using data from an Observable in its parent, and then utilizing the async pipe
to transform the data into a list of objects for rendering with *NgFor. Here's what I've done:
Create Observable Data in Parent Component:
// Parent Component dataSet$!: Observable<Data[]>; ngOnInit() { this.dataSet$ = this.serviceData.getData(); }
Pass Data from Parent to Child Using Async Pipe:
<!-- Parent Component Template --> <ng-container *ngIf="dataSet$ | async as dataSet"> <app-row-data-list *ngFor="let data of dataSet" [data]="data"></app-row-data-list> </ng-container>
Child Component with @Input Property:
// Child Component export class RowDataListComponent { @Input() data!: Data; }
Despite my efforts, the data is not displaying as expected, and the child components are not appearing.
I have tried implementing the solutions provided in the following responses:
However, none of these solutions resolved the issue. I have also conducted extensive research on this matter.
I have spent several hours trying to resolve this problem, so any assistance would be greatly appreciated.
Thank you.
Edit: Following guidance from one of the answers here, I was able to address the issue. I followed these steps (Refer to Stack Blitz example):
https://angular-ch...示例-uxz7dg.stackblitz.io