I have a component that can be nested and it tries to query its children.
@Component({
selector: "container",
template: `[{{this.children.length}}]<ng-content></ng-content>`
})
export class ContainerComponent {
@ContentChildren(ContainerComponent) public children:QueryList<ContainerComponent>;
}
However, the QueryList does not just include all child-components, but also the querying component itself (== this).
<container>
<container></container>
<container></container>
</container>
The output is [3][1][1] rather than [2][0][0].
https://plnkr.co/edit/mGuJEE60QUCXYb3jIYUx?p=preview
Can this be prevented? For DI there is @SkipSelf, but it doesn't seem to apply with @ContentChildren.
There is an open bug to get this changed and it was confirmed. This will change in the future.
https://github.com/angular/angular/issues/10098#issuecomment-235157642
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With