Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
Child component Input () data is undefined when loaded

I have a parent component and that needs to be loaded multiple child components. The child components are to be loaded by taking the object from parent, so far its working as expected. But the problem here is, I have a button to be rendered in the child component and the text of the button comes from parent component. If I click on that button the respective child component should open and the data which came from parent component should be shown in the child component, here whenever I click on child component button, the child component is getting opened but the input() data is getting undefined. Because of this the data from the parent component is not displaying in the child component when it is expanded. Here is the sample code :

parentcompoent.html :

<div *ngFor="let tile of tiles$ | async;">
<ng-container [ngTemplateOutlet]="$any(getSelectedComponentTemplete(tile.tileUrl))"
                    [ngTemplateOutletContext]="{ $implicit: {data:tile} }">
</ng-container>
</div>

<ng-template #card let-obj>
<app-child [data]="obj.data"></app-child>
</ng-template>`

parentcomponent.component.ts :

@ViewChild('card', { static: true }) card!: TemplateRef<any>;

getSelectedComponentTemplete(type: string) {
switch (type) {
case "card":
return this.card;
default:
return;
}

childcomponent.html :

<mat-card>
<mat-card-title>
<button [routerLink]="data?.cardUrl" [disableRipple]="true" mat-flat-button>{{data?.tileName}}</button>
</mat-card-title>
</mat-card>`

childcomponent.component.ts :

@Input()
data!: any;

ngOnInit(): void {
console.log(this.data);
}

I don't know why its loading perfectly when the child component is part of parent component and its not loading data when I click on the button in child component.

Can someone help me on this ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!