What is the read parameter in @ViewChild for

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
發佈了1 篇原創文章 · 獲贊 11 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章