首页 > 其他 > 详细

[Angular] ViewChild 'read' option

时间:2018-12-28 19:03:38      阅读:202      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!