Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mayankgupta688/444608affbdb56530a0399130c8c2ca0 to your computer and use it in GitHub Desktop.
Save Mayankgupta688/444608affbdb56530a0399130c8c2ca0 to your computer and use it in GitHub Desktop.
@Component({
selector: 'parent-component',
template: `
<div>
<b>This is the Parent Component Accessing Child Component</b>
<child-component #userInformation></child-component>
<input type="button" value="Update User Name" (click)="updateUserData()" />
</div>
`
})
export class ParentComponent implements OnInit {
@ViewChild("userInformation") childComponentReference: any;
updateUserData() {
// Accessing Property of Child Component
this.childComponentReference.userName = "Updated Name";
// Accessing Functions of Child Component
this.childComponentReference.updateUserName();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment