In Angular, I'm facing an issue when trying to pass data from one component to another on a click event. The structure of my components is as follows:
Parent Component
@Component({
selector: 'app-reporting-filter',
templateUrl: './reporting-filter.component.html',
styleUrls: ['./reporting-filter.component.scss'],
providers: [ProjectShipmentService]
})
export class ReportingFilterComponent implements DoCheck {
@ViewChild(TjlShipdateFilterComponent, {static: false})
private tjl: TjlShipdateFilterComponent;
finalResult: ShipDateFilterModel[];
click() {
this.elem = this.getResultOnFilter(this.firstSelection, this.secondSelection);
this.tjl.settDate(this.finalResult);
}
........}
Child Component Structure:
Component({
selector: 'app-tjl-shipdate-filter',
providers: [ProjectShipmentService],
templateUrl: './tjl-shipdate-filter.component.html',
styleUrls: ['./tjl-shipdate-filter.component.scss']
})
export class TjlShipdateFilterComponent implements DoCheck {
tljShipDate: ShipDateFilterModel[];
@Input() settDate(e: ShipDateFilterModel[]) {
this.tljShipDate = e;
}
......}
Content of reporting-filter.component.html:
<dxi-item [ratio]="1">
<dx-button (onClick)="click()" style="padding: 1vw 3vw 1.5vw 3vw; text-align: center; font-weight: bold;">Filter</dx-button>
</dxi-item>
However, upon clicking the button and executing 'this.tjl.settDate(this.finalResult);' in the parent component, I encounter the following error:
TypeError: Cannot read property 'settDate' of undefined
We are unsure if there is anything missing here.