I want to call function from parent component for get some datas but I can't. Not getting any error but it returns undefined. Where am I wrong?
parent.component
user:any
dataTest(){
console.log(this.user);
}
child.component
@ViewChild(AppLayoutComponent) profile!: AppLayoutComponent;
ngAfterViewInit():void{
this.profile?.dataTest()
}
this.profileinngAfterViewInitis maybeundefined. Validate it viaconsole.log. You get no error if you use optional chaining (?). Also you can only view childs withViewChildas the name already says. Not parents.undefined.@Inputfor pass data from parent to child.