I am trying to pass data that is dynamic to a child component. But I always get the data as undefined in the child component. Below is what I am doing.
ParentComp
You might try OnChanges lifecycle hook method.
In your case, you would need to add it to your child component like so:
ngOnChanges(changes) {
if (changes['dataNeeded'] && this.dataNeeded) {
console.log(this.dataNeeded);
}
}
PS Also I just noticed the wrong syntax in your ChildComponent.ts
, it is missing this
:
ngOnInit() {
console.log(this.dataNeeded);
}