Roberto Heckers’ Post

View profile for Roberto Heckers

Angular and Nx Specialist - Published author: Effective Angular

When using contentChildren in #Angular to access projected elements, by default, it only finds direct children, no descendants 🛑 If you use contentChildren to query a list of projected children, the component will only find them if they are projected as direct children. If you add a container of another nested structure in your projection content, contentChildren will not find the elements you are looking for 🤔 But there is a configuration for this, on contentChildren, you can add a descendants configuration, when you set this to true it will find the elements, but be carefull, because it will look all the way down the DOM tree, so you need to filter or scope correctly when using descendants true ✅

  • text
Fabian Birke

Fullstack Developer | Angular & .NET Spezialist | Software for Medical Technology

1mo

Great point! Utilizing the `descendants` configuration is essential when dealing with nested structures in Angular. However last weekend I found out that it is possible to use viewChild.required which drops the undefined type. This is really helpful :-)

Raphaël Tuong Tho VO

Senior Front End Developer | Angular Specialist | 10 years of experience

1mo

Thank Roberto, so it means it will look through the whole app, not only limited to the component where it is used, is it right ?

See more comments

To view or add a comment, sign in

Explore content categories