Nul*_*tor 6 private viewchild angular angular-aot angular7
如果模板中没有引用 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
看来是的,这没问题,因为您可能会发现它也在官方角度基础指南中完成,网址为:
组件和模板 > 组件交互 >父级调用 @ViewChild():
@ViewChild(CountdownTimerComponent) 私有timerComponent: CountdownTimerComponent;
| 归档时间: |
|
| 查看次数: |
2263 次 |
| 最近记录: |