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;
[Angular] ViewChild 'read' option
原文地址:https://www.cnblogs.com/Answer1215/p/10192285.html
时间: 2024-10-14 21:12:06