Angular ViewChildren с вложенными дочерними элементами

Документация для ContentChildren ясно заявляет, что QueryListне будет извлекать ничего внутри дочерних компонентов. То же самое дляViewChildren хотя, поэтому я спрашиваю себя, если что-то я делаю не так.

директива

@Directive({
  selector: '.input-group'
})
export class InputGroupDirective {

  constructor(private element: ElementRef) {
    console.log(element); // <-- produces n results
  }
}

parent.component.ts

@ViewChildren( InputGroupDirective ) public inputGroup: QueryList<InputGroupDirective>;

public ngAfterViewInit(): void {
  console.log(this.inputGroup); // <- produces empty result
  console.log(document.querySelector('.input-group')); // <-produces n results
}

parent.component.html

<child></child>

child.component.html

<second-child></second-child>

second.child.component.html

<div class="input-group"></div>

По сути, мне нужно выбрать первый .input-groupоднако во вложенных дочерних компонентах. Любые идеи?

0 ответов

Другие вопросы по тегам