Skip to content

ngModel complains when used with @defer #55028

@ssougnez

Description

@ssougnez

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

forms

Is this a regression?

No

Description

Say we have a component with a form.
One of the field is a cutstom component implementing ControlValueAccessor.
This component uses ngModel without ngModelOptions (which might be a bad practice, but it works).
When the component hosting the form is used without @defer, it works as expected, but as soon as it is used in a @defer block, the error "ngModel cannot be used to register form controls with a parent formGroup directive." is thrown.

I'm not sure whether it's a bad practice or not to use ngModel without ngModelOptions in that scenario but I think the behavior should be consistent whether you use @defer or not. Either it should fail every time or works every time.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-17-starter-project-egsglm

Please provide the exception or error you saw

Simply remove the @defer/@placeholder from the stackblitz to enable/disable the error.

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

Angular CLI: 17.2.3
Node: 20.11.1
Package Manager: yarn 1.22.19
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1702.2
@angular-devkit/build-angular   17.2.2
@angular-devkit/core            17.2.3
@angular-devkit/schematics      17.2.3
@schematics/angular             17.2.3
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2

Anything else?

No response

Metadata

Metadata

Assignees

Labels

P2The issue is important to a large percentage of users, with a workaroundarea: coreIssues related to the framework runtimecore: deferIssues related to @defer blocks.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions