Note: This does work for number fields with a caveat
Currently the NumberValueAccessor
(source) sets the value to null when the field is empty.
However, be cautious of this issue https://github.com/angular/angular/issues/55002
If you happen to be setting the input type
dynamically:
<input [type]="'number'" />
instead of
<input type="number" />
then the NumberValueAccessor
won't get triggered (because it can't match the selector statically at compile time) so the DefaultValueAccessor
will apply. In fact in that case ALL numbers will get set as strings to your ngModel
/ formControl