question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use ContentChildren with ngForTemplate

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior Getting directives with @ContentChildren does not work when the directives were created using ngForTemplate.

Expected behavior Directives inside repeated templates using ngForTemplate should be picked up by @ContentChildren like they would if you were using ng-content.

Minimal reproduction of the problem with instructions https://plnkr.co/edit/pt3fgjvL7yREdHKWl8IZ?p=preview

Check src/app.ts. You’ll see that the Marker directive is being repeated by the template passed to Repeater, but Repeater cannot use @ContentChildren to query for Markers.

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.

  • Angular version: 2.0.X 2.0.1
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] Tested in Chrome
  • Language: TypeScript 2
  • Node (for AoT issues): node --version =

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
timblakelycommented, Oct 12, 2016

I think I ran into this while exploring using ViewChildren/ContentChildren within custom structural directives. It appears ViewChildren and ContentChildren can’t see into views created by createEmbeddedView.

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).

0reactions
angular-automatic-lock-bot[bot]commented, Sep 14, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular @ContentChildren doesn´t work with <ng-template>
It appears that when wrapping the component in a ng-template , @ContentChildren fails to find the children rendered from a template.
Read more >
ngTemplateOutlet: The secret to customisation - Angular inDepth
In this article we demonstrate how to use ngTemplateOutlet, along with ngTemplateOutletContext, to make a component completely customisable.
Read more >
Angular ng-template, ng-container and ngTemplateOutlet
This is a Complete Guide To Angular Templates: it covers ng-template, ng-container, the ngTemplateOutlet structural directive, and more.
Read more >
Understanding Dynamic Scoping and TemplateRef
For this purpose we use the *ngFor directive. We will refer to directives and components by using their controller names or their selectors....
Read more >
[Solved]-Angular2 child component as data-angular.js
If you wrap the children in <template> tags you can access them using @ContentChildren() and insert them using *ngFor and *ngForTemplate .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found