The Stackblitz app linked below is an excerpt demonstrating Angular's guide sample showing how parent and child components can communicate. In this example, the parent references the child component via the @ViewChild
decorator, and then is able to invoke its methods.
The parent component's start
, stop
, and the seconds
methods are just wrappers for the child's components of the same name.
My question is, why are my child's methods so open without the option to keep them private? In my pasted code, i have already tried modifying the child's method to declare the methods as private
, and as you can see, it was to no avail, as the sample code still runs.
Can i make sure i can write up a component such that i can control which of its methods i want to expose to the parent container, and which of them i want to keep inaccessible for the parent?
- Stackblitz excerpt running sample: https://stackblitz.com/edit/angular-2s4mpj?file=src%2Fapp%2Fcountdown-timer.component.ts
- Angular guide page: https://angular.io/guide/component-interaction#parent-calls-an-viewchild