I am retrieving data from a db and data is ready I am trying to bind to a child element by using ViewChild so as to pass obj data to the child element
The issue is that the component is not "ready" so I set a timeout of 2 seconds.
This doesn't feel right. How would I know if the child component is ready.
Parent component retrieves data from the DB
@ViewChild("assumps") assumps: AssumptionsComponent
getProposalAmounts() {
this.targets.getProposalAmounts().subscribe((data) => {
this.assumptions = data.assumptions;
setTimeout(() => {
this.assumps.setAssumptionsForm(this.assumptions);
}, 2000)
Inside the child component
setAssumptionsForm(obj: Assumptions) {
if (obj != null) {
this.assumptionsObj = obj;
}
Without the timeout the child in null;
Error reads Cannot read property 'setAssumptionsForm' of undefined
Thank you
ngAfterViewInitand then, when is ready (if(!!this.assumps)) do your logic