Skip to content

writeValue gets called before ngOnInit #29218

@romansattler

Description

@romansattler

🐞 bug report

Affected Package

The issue is caused by package `@angular/forms`

Is this a regression?

I don't know. I don't think so.

Description

When NgControl is injected into the constructor of a component and the value accessor is set manually to avoid cyclic dependency errors, writeValue is called before ngOnInit.
This workaround is suggested by the Material Angular doc under ngControl.

🔬 Minimal Reproduction

Stackblitz

🌍 Your Environment

Angular Version:


Angular CLI: 7.3.5
Node: 11.9.0
OS: win32 x64
Angular: 7.2.8
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.5
@angular-devkit/build-angular     0.13.5
@angular-devkit/build-optimizer   0.13.5
@angular-devkit/build-webpack     0.13.5
@angular-devkit/core              7.3.5
@angular-devkit/schematics        7.3.5
@angular/cdk                      7.3.3
@angular/cli                      7.3.5
@angular/material                 7.3.3
@angular/pwa                      0.13.5
@ngtools/webpack                  7.3.5
@schematics/angular               7.3.5
@schematics/update                0.13.5
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.29.0

Anything else relevant?

I was sent here by the @angular/material2 team. They believe it's an issue with @angular/forms.
angular/components#15434

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions