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
однако во вложенных дочерних компонентах. Любые идеи?