-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ivy] ContentChildren doesn't pick up elements inside ng-container #34768
Comments
From what I can tell the issue isn't due to |
@henry-alakazhang as commented by @crisbeto I believe that Having said this, it is very easy to get the correct behaviour without using Given your first example you could do (shorter and <app-parent name="indirect with projectAs">
<app-child *ngFor="let i of [1, 2, 3, 4]" >
{{ i }}
</app-child>
</app-parent> If you want to have a group of sibling elements then you can use the de-sugared version of ngIf / ngFor: <app-parent>
<ng-template ngFor="..." [ngForOf]="...">
<app-child *ngIf="...">
</ng-template>
</app-parent> Queries with We are still debating what to do with |
I'm aware of what has been said above, but just to point something else out: respecting ngProjectAs for the ContentChild(ren) queries would lead to the odd question of what to populate the result with, since it's matched by something that isn't actually that component. So even if it worked, it wouldn't actually give you what you'd expect. |
@Airblader I'm sorry but I don't understand the use-case that you are describing... Could you put it in a stackblitz ? It looks like you are seeing something I'm not seeing... |
I was just describing that the premise of this issue — that ContentChildren should work with ngProjectAs — is a flawed idea because even if it was supposed to work (which it isn't), the query list couldn't possibly contain instances of that component since what was actually matched was a completely other element. |
Hey, thanks for the response. The de-sugared version does work, although it's a bit more complex than I'd like. Large-ish organisation; having to teach people to use the de-sugared version in a single use case; extra training and mental overhead; yada yada yada. I do feel like the |
That is exactly my point above, though: conceptually this gets tricky. Consider this:
Which query list would be filled – and more importantly: with what? Logically consistent would be if No instance of
which looks really odd, doesn't it? |
Hmm, yeah, I see your point now. It's fine for |
…descendants: false option Fixes angular#34768
…descendants: false option Fixes angular#34768
…descendants: false option Fixes angular#34768
…descendants: false option Fixes angular#34768
…descendants: false option Fixes angular#34768
…descendants: false option Fixes angular#34768
…descendants: false option Fixes angular#34768
…descendants: false option Before this change content queries with the `descendants: false` option, as implemented in ivy, would not descendinto `<ng-container>` elements. This behaviour was different from the way the View Engine worked. This change alligns ngIvy and VE behaviours when it comes to queries and the `<ng-container>` elements and fixes a common bugs where a query target was placed inside the `<ng-container>` element with a * directive on it. Before: ```html <needs-target> <ng-container *ngIf="condition"> <div #target>...</div> <!-- this node would NOT match --> </ng-container> </needs-target> ``` After: ```html <needs-target> <ng-container *ngIf="condition"> <div #target>...</div> <!-- this node WILL match --> </ng-container> </needs-target> ``` Fixes angular#34768
…descendants: false option (#35384) Before this change content queries with the `descendants: false` option, as implemented in ivy, would not descendinto `<ng-container>` elements. This behaviour was different from the way the View Engine worked. This change alligns ngIvy and VE behaviours when it comes to queries and the `<ng-container>` elements and fixes a common bugs where a query target was placed inside the `<ng-container>` element with a * directive on it. Before: ```html <needs-target> <ng-container *ngIf="condition"> <div #target>...</div> <!-- this node would NOT match --> </ng-container> </needs-target> ``` After: ```html <needs-target> <ng-container *ngIf="condition"> <div #target>...</div> <!-- this node WILL match --> </ng-container> </needs-target> ``` Fixes #34768 PR Close #35384
…nd demo-apps Related fixed Angular issue: angular/angular#34768 fixes: #197
…nd demo-apps Related fixed Angular issue: angular/angular#34768 fixes: #197
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 bug report
Affected Package
The issue is caused by package @angular/core@9.0.0-rc.8
Is this a regression?
Yes, the previous version in which this bug was not present was: v8
Description
ContentChildren
doesn't pick up things marked withngProjectAs
.In v8, the
ContentChildren
in theParentComponent
would pick up theapp-child
inside the ng-container (technically, it did this regardless ofngProjectAs
, but the point is it did work). In Ivy, it no longer picks up the children with or without anngProjectAs
. Given<ng-content select=*>
does work withngProjectAs
, it seems to me thatContentChildren
should as well.🔬 Minimal Reproduction
https://github.com/henry-alakazhang/angular-content-children-repro
Master branch is v9, v8 branch is v8.
https://github.com/henry-alakazhang/angular-content-children-repro/tree/v8
🌍 Your Environment
Angular Version:
Anything else relevant?
Related to #34289, but the suggested solution (
descendants: true
) is not always feasible. In my case, I want to be able to nest anotherparent
inside thechild
and usingdescendants: true
would pick up the nested children as well.Similarly, the other suggestion in the compatibility guide, to only use direct descendants, is difficult to use if I want to apply multiple structural directives to the child, eg.
The text was updated successfully, but these errors were encountered: