skip to content
Alvin Lucillo

Querying multiple projected content

/ 1 min read

Similar to yesterday, we can query multiple projected contents with contentChldren.

  <app-test>
    <div #test> Value 1</div>
    <div #test>Value 2</div>
  </app-test>

Child component with ng-content where projected/injected contents are rendered

<ng-content />
  testValues = contentChildren<ElementRef>('test');

  constructor() {
    effect(() => {
      console.log(
        'test values',
        this.testValues().map((v) => v.nativeElement.textContent)
      ); // test values (2) [' Value 1', 'Value 2']
    });
  }