Last active
March 11, 2021 11:56
-
-
Save Mayankgupta688/444608affbdb56530a0399130c8c2ca0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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