angular / angular/angular

Custom directive implementing controlValueAccessor does not trigger writeValue if the formControl has been updated by another controlValueAccessor

Open
#43,484 4 comments 17 reactions 0 assignees View on GitHub
area: forms P3
Dominant language
TypeScript
Stars
101k
Forks
27.5k
Avg merge
1d 19h
Merged PRs (30d)
288

Description

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

forms

### Is this a regression?

No

### Description

I've created a custom directive implementing controlValueAccessor and added it to two html input elements.

The writeValue function is not called if the input value is provided using [formControl] and the value is updated through the registerOnChange callback.

The writeValue is instead correctly called if the input value is provided by [(ngModel)] instead of [formControl]

```
Export class customDirective implements controlValueAccessor ...

With ngModel works fine

With formControl there's the issue

```

### Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-ivy-a2loir?file=src%2Fapp%2Fapp.component.html

### Please provide the exception or error you saw

_No response_

### Please provide the environment you discovered this bug in

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the linked StackBlitz reproduction and the @angular/forms implementation of ControlValueAccessor, comparing the [formControl] and [(ngModel)] binding paths. Trace the registerOnChange and writeValue calls for two controls sharing the same value, then add or update coverage so the reproduction behaves consistently and writeValue is invoked when the form control changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.