I have successfully passed values between Angular components using Input/Output several times before, but I am currently facing a unique situation for which I cannot find a solution:
There are two components involved:
- home.component (parent component)
The parent component contains another navigation component that displays tabs from an external library. This navigation component is responsible for loading the child component: "task.component".
html file:
<div>
<app-tabs [tabs]="tabs" [activeTab]="activeTab" (id)="onId($event)"></app-tabs>
</div>
ts file:
onId($event) {
// $event would contain the id obtained in the child component
}
- tasks.component (child component)
The child component has a button click event that needs to communicate with the parent component:
html file:
<button type="button" (click)="play('task/play', 30)">Play</button>
ts file:
@Output() id= new EventEmitter<number>();
play(url: string, id: number) {
this.tasksService.playTask(url).subscribe(
response => {
// Here, I need to access a method in the parent component.
// this.id.emit(id);
},
err => {
}
);
}
In previous cases, passing parameters between child and parent components was straightforward because I used custom components. However, when working with an intermediate tab component, this becomes a challenge. It seems that directly passing the "Output" to the "app-tabs" component is not feasible.
Any suggestions on how to overcome this issue?