[Angular] ViewChild 'read' option
Angular 39 Read option
2023-09-14 09:00:49 时间
It is not clear in the Docs about {read: xx} option for @ViewChild.
Based on the Source code, @ViewChild as view as Component, ElementRef, TemplateRef.
For example, we have:
<one></one>
@ViewChild(OneComponent)
one: OneComponent;
ngAfterViewInit() { console.log('after', this.one); }
Now we read 'OneComponent' as a component, if we want to read it as ElementRef, we can do:
@ViewChild(OneComponent, {read: ElementRef})
one: ElementRef;
[NOTICE]:
One thing to notice is that @ViewChild is only for viewing the its own component tamplate, you cannot view its child component template or parent component template
相关文章
- AngularJS进阶(五)Angular实现下拉菜单多选
- SAP 电商云 Spartacus UI Angular UI 和 Accelerator JSP UI 的混合使用
- angular子组件传值到父组件_vue子组件传值给父组件
- Angular SSR 和 PWA 结合起来使用的一些现象观察
- 【Angular教程】-组件通信|8月更文挑战
- 一款开源的 Angular Storefront 应用介绍,代号 Spartacus 诞生的历史背景
- Angular 应用里 ng-package.json 文件的作用是什么?
- 关于 Angular 应用的 Bootstrap 过程
- 备受 Vue、Angular 和 React 青睐的 Signals 演进史
- 关于 Angular 12 的 inlineCriticalCss 选项
- 基于豆瓣API+Angular开发的webApp
- angular.foreach循环方法使用指南
- 使用angular写一个helloworld