码迷,mamicode.com
首页 > 其他好文 > 详细

[Angular] ViewChild 'read' option

时间:2018-12-28 19:23:17      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:href   read   OLE   after   about   hub   view   example   temp   

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

标签:href   read   OLE   after   about   hub   view   example   temp   

原文地址:https://www.cnblogs.com/Answer1215/p/10192285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!