如果模板中没有引用 ViewChild,是否可以将其标记为私有?
我已经能够做到这一点,然后使用“--prod”标志构建和提供服务,并且没有遇到任何错误。我目前正在使用 Angular 7。
@ViewChild(HelloComponent) private helloComponent;
Run Code Online (Sandbox Code Playgroud)
这是我正在谈论的堆栈闪电战:https ://stackblitz.com/edit/angular-vxbpuk?file=src%2Fapp%2Fapp.component.ts
我想我有使用 aot 的 stackblitz,但你可以在本地验证同样的事情。
编辑:我很抱歉之前没有提出这个问题,但是角度文档中的这个模糊让我停下来:
https://angular.io/guide/aot-compiler#phase-2-code-generation
装饰组件类成员必须是公共的。您不能将 @Input() 属性设为私有或内部。
但正如@GCSDC 在下面已经指出的那样,Angular 团队似乎在他们的示例中使用了私有成员:https ://angular.io/guide/component-interaction#parent-calls-an-viewchild