-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
Which @angular/* package(s) are the source of the bug?
forms
Is this a regression?
No
Description
When working with controls, valueChanges stream is initially null. That goes kind of against the RxJS paradigm. When working with streams you expect to code regardless of time of execution and streams are specifically there to fix situation where you are dependent on value that is not there for the time being.
What makes it worse is it works differently for ngModel and formControl. Consider this directive:
@Directive({
standalone: true,
selector: '[valueChanges]',
})
export class ValueChangesDirective {
private readonly control = inject(NgControl);
@Output()
readonly valueChanges = defer(() => this.control.valueChanges!);
}By the time somebody subscribes to (valueChanges) output in the template, ngModel versions is ready, while FormControl version is not. This makes it impossible to reliably chain control value changes to directive outputs.
I realize these streams are recreated in ngOnChanges because FormControl is passed as input, rather than created internally as in ngModel, but it would be nice if those streams would exist since the beginning as subjects and controls would feed values to them, instead of recreating them.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/value-changes-issue
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version)
Angular 17
Anything else?
No response