-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Unable to use ContentChildren with ngForTemplate #12094
Comments
If you want to observe changes to directives rolled out by
while view:
|
@pkozlowski-opensource I suspected that, but tried that as well (see updated plunker: https://plnkr.co/edit/pt3fgjvL7yREdHKWl8IZ?p=preview). If this is an issue with Edit: This example is closer to my actual use-case: https://plnkr.co/edit/gmrBU9kRbQpATtySV6xh?p=preview |
I think I ran into this while exploring using Plunker here. Parent can't see a grandchild in either ViewChildren or ContentChildren. And a directive on the Child cannot see anything except a TemplateRef (see console logs). |
…t a different place Previously, if a `TemplateRef` was created in a `ViewContainerRef` at a different place, the content was not query able at all. With this change, the content of the template can be queried as if it was stamped out at the declaration place of the template. E.g. in the following example, the `QueryList<ChildCmp>` will be filled once the button is clicked. ``` @component({ selector: ‘my-comp’, template: ‘<button #vc (click)=“createView()”></button>’ }) class MyComp { @ContentChildren(ChildCmp) children: QueryList<ChildCmp>; @ContentChildren(TemplateRef) template: TemplateRef; @ViewChild(‘vc’, {read: ViewContainerRef}) vc: ViewContainerRef; createView() { this.vc.createEmbeddedView(this.template); } } @component({ template: ` <my-comp> <template><child-cmp></child-cmp></template> </my-comp> ` }) class App {} ``` Closes angular#12283 Closes angular#12094
…t a different place Previously, if a `TemplateRef` was created in a `ViewContainerRef` at a different place, the content was not query able at all. With this change, the content of the template can be queried as if it was stamped out at the declaration place of the template. E.g. in the following example, the `QueryList<ChildCmp>` will be filled once the button is clicked. ``` @component({ selector: ‘my-comp’, template: ‘<button #vc (click)=“createView()”></button>’ }) class MyComp { @ContentChildren(ChildCmp) children: QueryList<ChildCmp>; @ContentChildren(TemplateRef) template: TemplateRef; @ViewChild(‘vc’, {read: ViewContainerRef}) vc: ViewContainerRef; createView() { this.vc.createEmbeddedView(this.template); } } @component({ template: ` <my-comp> <template><child-cmp></child-cmp></template> </my-comp> ` }) class App {} ``` Closes angular#12283 Closes angular#12094
…t a different place Previously, if a `TemplateRef` was created in a `ViewContainerRef` at a different place, the content was not query able at all. With this change, the content of the template can be queried as if it was stamped out at the declaration place of the template. E.g. in the following example, the `QueryList<ChildCmp>` will be filled once the button is clicked. ``` @component({ selector: ‘my-comp’, template: ‘<button #vc (click)=“createView()”></button>’ }) class MyComp { @ContentChildren(ChildCmp) children: QueryList<ChildCmp>; @ContentChildren(TemplateRef) template: TemplateRef; @ViewChild(‘vc’, {read: ViewContainerRef}) vc: ViewContainerRef; createView() { this.vc.createEmbeddedView(this.template); } } @component({ template: ` <my-comp> <template><child-cmp></child-cmp></template> </my-comp> ` }) class App {} ``` Closes angular#12283 Closes angular#12094
So, there is still no way to use "ContentChildren" with views created using "createEmbeddedView"? @timblakely |
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. |
I'm submitting a ... (check one with "x")
Current behavior
Getting directives with
@ContentChildren
does not work when the directives were created usingngForTemplate
.Expected behavior
Directives inside repeated templates using
ngForTemplate
should be picked up by@ContentChildren
like they would if you were usingng-content
.Minimal reproduction of the problem with instructions
https://plnkr.co/edit/pt3fgjvL7yREdHKWl8IZ?p=preview
Check
src/app.ts
. You'll see that theMarker
directive is being repeated by the template passed toRepeater
, butRepeater
cannot use@ContentChildren
to query forMarker
s.What is the motivation / use case for changing the behavior?
In general, this seems like it should work. My specific use case is making a pair of components, each that use
ngForTemplate
with one used inside the others template. Together they allow filtering of a collection whose items have sub-items. One feature is that if all items have been filtered out (IE, no matching results) a message should be shown. I would assume the way to do this would be to query for items from the parent and subscribe to changes.Please tell us about your environment:
Reproducible in Plunker.
2.0.1
Tested in Chrome
node --version
=The text was updated successfully, but these errors were encountered: