Fetching an Element Reference Using @ContentChild | Task

Ole Ersoy
Dec - 20  -  1 min

Scenario

We want to measure the height of our CardHeaderComponent and therefore need to obtain its host element.

Approach

Pass in { read: ElementRef } to @ContentChildren letting the annotation know that we are interested in the host element for the CardHeaderComponent.

@ContentChildren(CardHeaderComponent, { read: ElementRef }) 
  headers: QueryList<ElementRef>;

Demo