What is the read parameter in @ViewChild for

本文解释了Angular框架中ViewChild装饰器的read参数用途。通过使用ViewChild和read参数,开发者可以获取到模板变量所关联的不同类型的实例,如ElementRef、ViewContainerRef或应用到特定标签上的组件实例和指令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

There can be several instances of various types be associated with the element tag with the #mynametemplate variable.

For each element there is an ElementRef and ViewContainerRef (maybe others from components or directives applied to that tag).

If the element is a component, then there is the component instance.

There can also be one or several directives applied to the element

With {read: SomeType} you tell what type should be returned from the element with the #mynametemplate variable.

If you don't provide the read parameter, @ViewChild() returns the

  • ElementRef instance if there is no component applied, or the
  • component instance if there is.
  • If you want to get something different you need to explicitely tell using read
原文链接: http://stackoverflow.com/questions/37450805/what-is-the-read-parameter-in-viewchild-for/37476195#37476195
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值