Skip to content

Using viewChild/viewChildren with private property should be an error #54863

@csvn

Description

@csvn

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

Using a private property (e.g. #children) with viewChildren() or viewChild() will silently fail, and never update the counts. This is likely also the same for contentChild() and contentChildren(). This also means that retrieving the signal in an effect() will also never trigger outside of the initial run.

Current workaround is to use private myProp = viewChildren('selector');, which will work as intended while still hiding the property from being public.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-lsgmpz?file=src%2Fmain.ts

Please provide the exception or error you saw

A `viewChildren()` on a public property (`elements`) will log 1, while a `viewChildren()` on private property (`#elements`) will log 0.

Please provide the environment you discovered this bug in (run ng version)

Angular: 17.3.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.0
@angular-devkit/build-angular   17.3.0
@angular-devkit/core            17.3.0
@angular-devkit/schematics      17.3.0
@schematics/angular             17.3.0
rxjs                            7.8.1
typescript                      5.3.3
zone.js                         0.14.4

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions