Is it okay to mark a ViewChild as private, if it's not being referenced in the template?
I have been able to do this, then build and serve with the '--prod' flag, and encountered no errors. I'm currently using Angular 7.
@ViewChild(HelloComponent) private helloComponent;
Here's a stackblitz to what I'm talking about:
https://stackblitz.com/edit/angular-vxbpuk?file=src%2Fapp%2Fapp.component.ts
I think I have the stackblitz using aot, but you could verify the same thing locally.
EDIT: I apologize for not bringing this up before, but there's this blurb from the angular doc that give me pause:
https://angular.io/guide/aot-compiler#phase-2-code-generation
Decorated component class members must be public. You cannot make an @Input() property private or internal.
But as @GCSDC already pointed out below, the Angular team seems to be using private members in their examples:
https://angular.io/guide/component-interaction#parent-calls-an-viewchild
private
is OK but an ES class #private field would not be -- see github.com/microsoft/TypeScript/issues/31670 for a big discussion about why they're keeping both – Renferd